-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.js
40 lines (31 loc) · 1019 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
const winston = require('winston')
const { createLogger, format, transports } = winston
const { combine, timestamp, label, printf } = format
const logFormat = printf(info => {
return `${info.timestamp} [${info.label}] ${info.level}: ${info.message} `;
})
Object.prototype.toJSONString = function() {
return JSON.stringify(this)
}
var instance = null
const setupLoggers = () => {
const logger = createLogger({
format: combine(
label({ label: 'ExampleApp' }),
timestamp(),
logFormat
),
transports: [new winston.transports.File({ filename: 'error.log', level: 'error' }),
new winston.transports.File({ filename: 'info.log', level: 'info' }),
new winston.transports.File({ filename: 'debug.log', level: 'debug' }),
new winston.transports.File({ filename: 'blackbox.log' })]
})
instance = logger
}
const getLogger = () => {
if(instance === null || instance === undefined) {
setupLoggers()
}
return instance
}
module.exports = {getLogger,setupLoggers}