-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.js
42 lines (38 loc) · 978 Bytes
/
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
const { createLogger, format, transports } = require('winston');
const logsLocation = './logs/';
const logger = createLogger({
level: 'info',
format: format.combine(
format.timestamp({
format: 'YYYY-MM-DD HH:mm:ss',
}),
format.errors({ stack: true }),
format.splat(),
format.json()
),
transports: [
//
// - Write to all logs with level `info` and below to `combined.log`.
// - Write all logs error (and below) to `error.log`.
//
new transports.File({
filename: logsLocation + 'error.log',
level: 'error',
}),
new transports.File({
filename: logsLocation + 'combined.log',
}),
],
});
//
// If we're not in production then **ALSO** log to the `console`
// with the colorized simple format.
//
if (process.env.NODE_ENV !== 'production') {
logger.add(
new transports.Console({
format: format.combine(format.colorize(), format.simple()),
})
);
}
module.exports = { logger };