wikijs-fork/server/core/logger.js
Marián Skrip 2815f38c52
feat(logging): add option to configure JSON logging (#5022)
* fix: Use logger for logs using console logging

* feat: Add option to configure JSON logging

* fix: use generic logFormat instead of json specific

* fix: use logFormat for docker config

* fix: use logFormat to build winston formatters

Co-authored-by: Nicolas Giard <github@ngpixel.com>
2022-02-18 19:48:22 -05:00

45 lines
1.2 KiB
JavaScript

// const _ = require('lodash')
const winston = require('winston')
/* global WIKI */
module.exports = {
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)
})
// Init Console (default)
logger.add(new winston.transports.Console({
level: WIKI.config.logLevel,
prettyPrint: true,
colorize: true,
silent: false,
timestamp: true
}))
// _.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
// })
return logger
}
}