-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
47 lines (39 loc) · 978 Bytes
/
index.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
const Transport = require('winston-transport');
const logger = require('gelf-pro');
const levels = {
emerg: 'emergency',
alert: 'alert',
crit: 'critical',
error: 'error',
warn: 'warn',
notice: 'notice',
info: 'info',
debug: 'debug',
};
class GelfTransport extends Transport {
constructor(opts) {
super(opts);
this.logger = Object.create(logger);
this.logger.setConfig(opts.gelfPro);
}
log({level, message, ...extra}, callback) {
setImmediate(() => {
this.emit('logged', {level, message, extra});
});
if (typeof extra === 'object') {
for (const key in extra) {
const value = extra[key];
if (value instanceof Error) {
extra = value;
}
}
}
const graylogLevel = levels[level] || levels.info;
this.logger[graylogLevel](message, extra);
callback();
}
setConfig(opts) {
this.logger.setConfig(opts.gelfPro);
}
}
module.exports = exports = GelfTransport;