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>
This commit is contained in:
@@ -19,7 +19,7 @@ module.exports = {
|
||||
} catch (err) {
|
||||
WIKI.logger.error('Database Initialization Error: ' + err.message)
|
||||
if (WIKI.IS_DEBUG) {
|
||||
console.error(err)
|
||||
WIKI.logger.error(err)
|
||||
}
|
||||
process.exit(1)
|
||||
}
|
||||
|
@@ -6,14 +6,21 @@ const winston = require('winston')
|
||||
module.exports = {
|
||||
loggers: {},
|
||||
init(uid) {
|
||||
let logger = winston.createLogger({
|
||||
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(
|
||||
winston.format.colorize(),
|
||||
winston.format.label({ label: uid }),
|
||||
winston.format.timestamp(),
|
||||
winston.format.printf(info => `${info.timestamp} [${info.label}] ${info.level}: ${info.message}`)
|
||||
)
|
||||
format: winston.format.combine(...loggerFormats)
|
||||
})
|
||||
|
||||
// Init Console (default)
|
||||
|
Reference in New Issue
Block a user