-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinitLogger.js
45 lines (41 loc) · 1.02 KB
/
initLogger.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
const winston = require('winston')
const logDir = require('./config').log.dir
const path = require('path')
const transports = [
new (winston.transports.File)({
name: 'info-file',
filename: path.resolve(logDir, 'messages.log'),
level: 'info',
timestamp: true,
json: false,
prettyPrint: true
}),
new (winston.transports.File)({
name: 'warn-file',
filename: path.resolve(logDir, 'warnings.log'),
level: 'warn',
timestamp: true,
json: false,
prettyPrint: true
}),
new (winston.transports.File)({
name: 'error-file',
filename: path.resolve(logDir, 'errors.log'),
level: 'error',
timestamp: true,
json: false,
prettyPrint: true,
handleExceptions: true
})
]
if (process.env.NODE_ENV !== 'production') {
transports.push(new (winston.transports.Console)({
name: 'debug-console',
level: 'debug',
colorize: true,
timestamp: true,
prettyPrint: true
}))
}
const logger = new (winston.Logger)({ transports: transports })
module.exports = logger