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:
parent
69e9ccc636
commit
2815f38c52
@ -108,6 +108,13 @@ bindIP: 0.0.0.0
|
|||||||
|
|
||||||
logLevel: info
|
logLevel: info
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------
|
||||||
|
# Log Format
|
||||||
|
# ---------------------------------------------------------------------
|
||||||
|
# Output format for logging, possible values: default, json
|
||||||
|
|
||||||
|
logFormat: default
|
||||||
|
|
||||||
# ---------------------------------------------------------------------
|
# ---------------------------------------------------------------------
|
||||||
# Offline Mode
|
# Offline Mode
|
||||||
# ---------------------------------------------------------------------
|
# ---------------------------------------------------------------------
|
||||||
|
@ -16,4 +16,5 @@ ssl:
|
|||||||
domain: $(LETSENCRYPT_DOMAIN)
|
domain: $(LETSENCRYPT_DOMAIN)
|
||||||
subscriberEmail: $(LETSENCRYPT_EMAIL)
|
subscriberEmail: $(LETSENCRYPT_EMAIL)
|
||||||
logLevel: info
|
logLevel: info
|
||||||
|
logFormat: $(LOG_FORMAT)
|
||||||
ha: $(HA_ACTIVE)
|
ha: $(HA_ACTIVE)
|
||||||
|
@ -19,7 +19,7 @@ module.exports = {
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
WIKI.logger.error('Database Initialization Error: ' + err.message)
|
WIKI.logger.error('Database Initialization Error: ' + err.message)
|
||||||
if (WIKI.IS_DEBUG) {
|
if (WIKI.IS_DEBUG) {
|
||||||
console.error(err)
|
WIKI.logger.error(err)
|
||||||
}
|
}
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
}
|
}
|
||||||
|
@ -6,14 +6,21 @@ const winston = require('winston')
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
loggers: {},
|
loggers: {},
|
||||||
init(uid) {
|
init(uid) {
|
||||||
let logger = winston.createLogger({
|
const loggerFormats = [
|
||||||
level: WIKI.config.logLevel,
|
|
||||||
format: winston.format.combine(
|
|
||||||
winston.format.colorize(),
|
|
||||||
winston.format.label({ label: uid }),
|
winston.format.label({ label: uid }),
|
||||||
winston.format.timestamp(),
|
winston.format.timestamp()
|
||||||
winston.format.printf(info => `${info.timestamp} [${info.label}] ${info.level}: ${info.message}`)
|
]
|
||||||
)
|
|
||||||
|
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)
|
// Init Console (default)
|
||||||
|
@ -73,7 +73,7 @@ module.exports = {
|
|||||||
mode: 0o600
|
mode: 0o600
|
||||||
})
|
})
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err)
|
WIKI.logger.error(err)
|
||||||
throw err
|
throw err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user