forked from bragma/winston-azure-application-insights
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloadIt.js
84 lines (68 loc) · 2 KB
/
loadIt.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
'use strict';
const winston = require('winston');
const aiLogger = require('./lib/winston-azure-application-insights').AzureApplicationInsightsLogger;
winston.level = 'debug';
configureLogging();
setInterval(() => {
loopIt();
}, 5000);
function loopIt() {
winston.info("Let's log something new...");
winston.error("This is an error log!");
winston.warn("And this is a warning message.");
winston.log("info", "Log with some metadata", {
question: "Answer to the Ultimate Question of Life, the Universe, and Everything",
answer: 42
});
function ExtendedError(message, arg1, arg2) {
this.message = message;
this.name = "ExtendedError";
this.arg1 = arg1;
this.arg2 = arg2;
Error.captureStackTrace(this, ExtendedError);
}
ExtendedError.prototype = Object.create(Error.prototype);
ExtendedError.prototype.constructor = ExtendedError;
winston.error("Log extended errors with properites", new ExtendedError("some error", "answer", 42));
}
function configureLogging() {
winston.setLevels({
trace: 9,
input: 8,
verbose: 7,
prompt: 6,
debug: 5,
info: 4,
data: 3,
help: 2,
warn: 1,
error: 0
});
winston.addColors({
trace: 'magenta',
input: 'grey',
verbose: 'cyan',
prompt: 'grey',
debug: 'blue',
info: 'green',
data: 'grey',
help: 'cyan',
warn: 'yellow',
error: 'red'
});
winston.remove(winston.transports.Console)
winston.add(winston.transports.Console, {
level: 'trace',
prettyPrint: true,
colorize: true,
silent: false,
timestamp: false
});
if (process.env.PROD && process.env.AIKEY) {
winston.add(aiLogger, {
key: process.env.AIKEY
});
winston.warn(`AppInsights logging on with key ${process.env.AIKEY}`);
}
winston.warn('log level set to %s', winston.level);
}