-
Notifications
You must be signed in to change notification settings - Fork 1
/
logger.js
54 lines (48 loc) · 1.4 KB
/
logger.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
const { Transform, pipeline } = require("stream");
const Transport = require("winston-transport");
const winston = require("winston");
const { LaunchDarklyTransportFilter, LD_CONTEXT } = require("./logger-transport");
const levels = {
user: -1,
emerg: 0,
alert: 1,
crit: 2,
error: 3,
warn: 4,
notice: 5,
info: 6,
debug: 7,
};
const file = new winston.transports.File({
filename: "combined.log",
name: "file",
});
const ldTransport = new LaunchDarklyTransportFilter({
levels,
defaultLevel: "debug",
flagKey: "config-log-verbosity",
});
ldTransport.pipe(file);
const logger = winston.createLogger({
levels: levels,
level: null,
transports: [ldTransport],
format: winston.format.combine(
winston.format.timestamp({
format: "YYYY-MM-DD HH:mm:ss",
}),
winston.format.colorize(),
winston.format.splat(),
winston.format.printf(({ timestamp, level, message, ...rest }) => {
return `${timestamp} [${level}]: ${message} ${JSON.stringify(rest)}`;
})
),
});
module.exports.logger = logger;
module.exports.levels = levels;
module.exports.setDefaultLogLevel = (level) =>
(ldTransport.defaultLevel = level);
module.exports.getDefaultLogLevel = () => ldTransport.defaultLevel;
module.exports.setLoggerLDClient = (c) => ldTransport.setLDClient(c);
module.exports.setDefaultLogContext = (c) => ldTransport.setDefaultContext(c);
module.exports.LD_CONTEXT = LD_CONTEXT;