2021-06-12 07:05:47 +08:00
|
|
|
import {createLogger, format, transports, Logger} from "winston";
|
2015-06-01 18:04:25 +08:00
|
|
|
|
2021-06-12 07:22:04 +08:00
|
|
|
type CodiMDLogger = Logger & {
|
2021-06-12 07:05:47 +08:00
|
|
|
stream: any
|
2021-06-12 07:22:04 +08:00
|
|
|
setLevel?: (string) => void
|
2021-06-12 07:05:47 +08:00
|
|
|
}
|
|
|
|
|
2021-06-12 07:22:04 +08:00
|
|
|
let logger: CodiMDLogger = createLogger({
|
2018-11-13 23:29:33 +01:00
|
|
|
level: 'debug',
|
|
|
|
format: format.combine(
|
|
|
|
format.uncolorize(),
|
|
|
|
format.timestamp(),
|
|
|
|
format.align(),
|
|
|
|
format.splat(),
|
|
|
|
format.printf(info => `${info.timestamp} ${info.level}: ${info.message}`)
|
|
|
|
),
|
2017-03-08 18:45:51 +08:00
|
|
|
transports: [
|
2018-11-13 23:29:33 +01:00
|
|
|
new transports.Console({
|
|
|
|
handleExceptions: true
|
2017-03-08 18:45:51 +08:00
|
|
|
})
|
|
|
|
],
|
|
|
|
exitOnError: false
|
|
|
|
})
|
2018-11-16 11:42:52 +01:00
|
|
|
|
|
|
|
logger.stream = {
|
|
|
|
write: function (message, encoding) {
|
|
|
|
logger.info(message)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-12 07:22:04 +08:00
|
|
|
logger.setLevel = function (level) {
|
|
|
|
logger.level = level
|
|
|
|
}
|
|
|
|
|
2021-06-12 07:05:47 +08:00
|
|
|
export = logger
|