wikijs-fork/server/core/logger.js

45 lines
1.2 KiB
JavaScript
Raw Permalink Normal View History

2018-06-11 03:23:09 +00:00
// const _ = require('lodash')
const winston = require('winston')
2017-03-29 00:19:01 +00:00
/* global WIKI */
2017-07-29 21:33:08 +00:00
module.exports = {
2017-12-24 05:34:47 +00:00
loggers: {},
init(uid) {
const loggerFormats = [
winston.format.label({ label: uid }),
winston.format.timestamp()
]
if (WIKI.config.logFormat === 'json') {
loggerFormats.push(winston.format.json())
} else {
loggerFormats.push(winston.format.colorize())
loggerFormats.push(winston.format.printf(info => `${info.timestamp} [${info.label}] ${info.level}: ${info.message}`))
}
const logger = winston.createLogger({
level: WIKI.config.logLevel,
format: winston.format.combine(...loggerFormats)
2017-07-29 21:33:08 +00:00
})
2017-03-29 00:19:01 +00:00
2018-06-11 03:23:09 +00:00
// Init Console (default)
2018-09-01 19:15:44 +00:00
logger.add(new winston.transports.Console({
level: WIKI.config.logLevel,
prettyPrint: true,
colorize: true,
silent: false,
timestamp: true
}))
2018-06-11 03:23:09 +00:00
// _.forOwn(_.omitBy(WIKI.config.logging.loggers, s => s.enabled === false), (loggerConfig, loggerKey) => {
// let loggerModule = require(`../modules/logging/${loggerKey}`)
// 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
}