-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
51 lines (40 loc) · 1.33 KB
/
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
48
49
50
51
const syslog = require("modern-syslog");
class SyslogHandler {
constructor(opts) {
// See https://github.com/strongloop/modern-syslog
// for more info about the flags
this.cfg = Object.assign({
ident: process.title,
flags: syslog.LOG_PID,
facility: syslog.LOG_LOCAL0,
}, opts);
console.log(this.cfg);
syslog.open(this.cfg.ident, this.cfg.flags, this.cfg.facility);
}
handleLog(logMsg) {
const opts = {};
// TODO: Test the performance impact of a switch lookup table vs.
// a dictionary based one.
let level = syslog.level.LOG_INFO;
switch (logMsg.level) {
case logMsg.logger.LEVEL_ERROR:
level = syslog.level.LOG_ERR;
break;
case logMsg.logger.LEVEL_WARN:
level = syslog.level.LOG_WARNING;
break;
case logMsg.logger.LEVEL_INFO:
level = syslog.level.LOG_INFO;
break;
case logMsg.logger.LEVEL_DEBUG:
level = syslog.level.LOG_DEBUG;
break;
}
const msg = logMsg.getPlainMessage();
syslog.log(level, msg);
console.log(level, " = ", msg);
}
}
SyslogHandler.flag = syslog.option;
SyslogHandler.facility = syslog.facility;
module.exports = SyslogHandler;