2017-12-24 05:34:47 +00:00
|
|
|
const _ = require('lodash')
|
2018-02-04 05:53:13 +00:00
|
|
|
const cluster = require('cluster')
|
2018-03-12 04:09:54 +00:00
|
|
|
const winston = require('winston')
|
2017-03-29 00:19:01 +00:00
|
|
|
|
2018-03-05 20:49:36 +00:00
|
|
|
/* global WIKI */
|
2018-02-04 05:53:13 +00:00
|
|
|
|
2017-07-29 21:33:08 +00:00
|
|
|
module.exports = {
|
2017-12-24 05:34:47 +00:00
|
|
|
loggers: {},
|
2017-07-29 21:33:08 +00:00
|
|
|
init() {
|
2018-03-12 04:09:54 +00:00
|
|
|
let logger = winston.createLogger({
|
2018-03-05 20:49:36 +00:00
|
|
|
level: WIKI.config.logLevel,
|
2018-03-12 04:09:54 +00:00
|
|
|
format: winston.format.combine(
|
|
|
|
winston.format.colorize(),
|
|
|
|
winston.format.label({ label: (cluster.isMaster) ? 'MASTER' : `WORKER-${cluster.worker.id}` }),
|
|
|
|
winston.format.timestamp(),
|
|
|
|
winston.format.printf(info => `${info.timestamp} [${info.label}] ${info.level}: ${info.message}`)
|
|
|
|
)
|
2017-07-29 21:33:08 +00:00
|
|
|
})
|
2017-03-29 00:19:01 +00:00
|
|
|
|
2018-03-05 20:49:36 +00:00
|
|
|
_.forOwn(_.omitBy(WIKI.config.logging.loggers, s => s.enabled === false), (loggerConfig, loggerKey) => {
|
2018-02-04 05:53:13 +00:00
|
|
|
let loggerModule = require(`../modules/logging/${loggerKey}`)
|
2017-12-24 05:34:47 +00:00
|
|
|
loggerModule.init(logger, loggerConfig)
|
|
|
|
this.loggers[logger.key] = loggerModule
|
|
|
|
})
|
2017-03-30 01:49:30 +00:00
|
|
|
|
2017-07-29 21:33:08 +00:00
|
|
|
return logger
|
|
|
|
}
|
2017-03-29 00:19:01 +00:00
|
|
|
}
|