2017-07-23 03:56:46 +00:00
|
|
|
/* global wiki */
|
|
|
|
|
2017-07-29 04:11:22 +00:00
|
|
|
const cluster = require('cluster')
|
2017-12-24 05:34:47 +00:00
|
|
|
const _ = require('lodash')
|
|
|
|
const fs = require('fs-extra')
|
|
|
|
const path = require('path')
|
2017-03-29 00:19:01 +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() {
|
|
|
|
let winston = require('winston')
|
2017-03-29 00:19:01 +00:00
|
|
|
|
2017-07-29 21:33:08 +00:00
|
|
|
let logger = new (winston.Logger)({
|
2017-12-17 04:41:16 +00:00
|
|
|
level: wiki.config.logLevel,
|
2017-12-24 05:34:47 +00:00
|
|
|
transports: []
|
2017-07-29 21:33:08 +00:00
|
|
|
})
|
2017-04-28 22:46:27 +00:00
|
|
|
|
2017-07-29 21:33:08 +00:00
|
|
|
logger.filters.push((level, msg) => {
|
|
|
|
let processName = (cluster.isMaster) ? 'MASTER' : `WORKER-${cluster.worker.id}`
|
|
|
|
return '[' + processName + '] ' + msg
|
|
|
|
})
|
2017-03-29 00:19:01 +00:00
|
|
|
|
2017-12-24 05:34:47 +00:00
|
|
|
_.forOwn(_.omitBy(wiki.config.logging.loggers, s => s.enabled === false), (loggerConfig, loggerKey) => {
|
|
|
|
let loggerModule = require(`../extensions/logging/${loggerKey}`)
|
|
|
|
loggerModule.init(logger, loggerConfig)
|
|
|
|
fs.readFile(path.join(wiki.ROOTPATH, `assets/svg/auth-icon-${loggerKey}.svg`), 'utf8').then(iconData => {
|
|
|
|
logger.icon = iconData
|
|
|
|
}).catch(err => {
|
|
|
|
if (err.code === 'ENOENT') {
|
|
|
|
logger.icon = '[missing icon]'
|
|
|
|
} else {
|
|
|
|
logger.error(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
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
|
|
|
}
|