This repository has been archived by the owner on Nov 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
winstonlogger.js
65 lines (52 loc) · 1.61 KB
/
winstonlogger.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
const winston = require('winston');
const LoggerInterface = require('./loggerinterface');
const logFormat = winston.format.printf((info) => {
return `${info.timestamp} [${info.level}]: ${info.message}`;
});
module.exports = class WinstonLogger extends LoggerInterface {
constructor(defaultLogLevel) {
super(defaultLogLevel);
this.winston = winston.createLogger({
level: this.logLevel,
format: winston.format.combine(
winston.format.colorize(),
winston.format.timestamp(),
logFormat
),
transports: [
new winston.transports.Console()
],
levels: {
debug: 0,
info: 1,
warning: 2,
error: 3
}
});
winston.addColors({
info: 'cyan',
debug: 'green',
warning: 'yellow',
error: 'red'
});
}
info(message, params) {
params = this.argumentsToArray(arguments).slice(1);
this.winston.info(message, ...params);
}
debug(message, params) {
params = this.argumentsToArray(arguments).slice(1);
this.winston.debug(message, ...params);
}
warning(message, params) {
params = this.argumentsToArray(arguments).slice(1);
this.winston.warning(message, ...params);
}
error(message, params) {
params = this.argumentsToArray(arguments).slice(1);
this.winston.error(message, ...params);
}
onLogLevelChange(level) {
this.winston.level = level;
}
}