mirror of https://github.com/requarks/wiki
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.1 KiB
41 lines
1.1 KiB
7 years ago
|
const _ = require('lodash')
|
||
7 years ago
|
const cluster = require('cluster')
|
||
7 years ago
|
const fs = require('fs-extra')
|
||
|
const path = require('path')
|
||
8 years ago
|
|
||
7 years ago
|
/* global wiki */
|
||
|
|
||
8 years ago
|
module.exports = {
|
||
7 years ago
|
loggers: {},
|
||
8 years ago
|
init() {
|
||
|
let winston = require('winston')
|
||
8 years ago
|
|
||
8 years ago
|
let logger = new (winston.Logger)({
|
||
7 years ago
|
level: wiki.config.logLevel,
|
||
7 years ago
|
transports: []
|
||
8 years ago
|
})
|
||
8 years ago
|
|
||
8 years ago
|
logger.filters.push((level, msg) => {
|
||
|
let processName = (cluster.isMaster) ? 'MASTER' : `WORKER-${cluster.worker.id}`
|
||
|
return '[' + processName + '] ' + msg
|
||
|
})
|
||
8 years ago
|
|
||
7 years ago
|
_.forOwn(_.omitBy(wiki.config.logging.loggers, s => s.enabled === false), (loggerConfig, loggerKey) => {
|
||
7 years ago
|
let loggerModule = require(`../modules/logging/${loggerKey}`)
|
||
7 years ago
|
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
|
||
|
})
|
||
8 years ago
|
|
||
8 years ago
|
return logger
|
||
|
}
|
||
8 years ago
|
}
|