forked from Commit451/skyhook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoggerUtil.ts
33 lines (28 loc) · 1009 Bytes
/
LoggerUtil.ts
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
import moment from 'moment'
import winston from 'winston'
/**
* Helps with logging things. Basically a Winston helper
*/
class LoggerUtil {
public static init() {
if (!this.isInitialized) {
// @ts-ignore Method exists, will be added to ts def in next release.
winston.loggers.add('logger', {
format: winston.format.combine(
winston.format.colorize(),
winston.format.printf((info) => `[${moment().format('YYYY-MM-DD hh:mm:ss').trim()}] [${info.level}]: ${info.message}`)
),
level: process.env.PRODUCTION ? 'info' : 'debug',
transports: [
new winston.transports.Console()
]
})
}
}
public static logger() {
// @ts-ignore Method exists, will be added to ts def in next release.
return winston.loggers.get('logger')
}
private static isInitialized = false
}
export { LoggerUtil }