-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-logger.js
37 lines (33 loc) · 974 Bytes
/
create-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
const winston = require('winston');
/**
* This method creates a winston logger.
* @param level The output level of the logger.
*/
function createLogger(level) {
const myFormat = winston.format.printf(({level, message, timestamp}) => {
// No timestamp (for logfile comparison)
// return `${level} ${timestamp} : ${message}`;
return `${level}: ${message}`;
});
const logger = winston.createLogger({
format: winston.format.combine(
winston.format.errors({stack: true}),
winston.format.splat(),
winston.format.timestamp()
),
exitOnError: false, // do not exit on handled exceptions
transports: [
new winston.transports.Console({
level,
format: winston.format.combine(
// no colors (to avoid escape sequences in tee'd file)
// winston.format.colorize(),
myFormat
),
silent: !level
})
]
});
return logger;
}
module.exports = createLogger;