diff --git a/config.sample.yml b/config.sample.yml index 6f4fbdf3..47edd8d2 100644 --- a/config.sample.yml +++ b/config.sample.yml @@ -108,6 +108,13 @@ bindIP: 0.0.0.0 logLevel: info +# --------------------------------------------------------------------- +# Log Format +# --------------------------------------------------------------------- +# Output format for logging, possible values: default, json + +logFormat: default + # --------------------------------------------------------------------- # Offline Mode # --------------------------------------------------------------------- diff --git a/dev/build/config.yml b/dev/build/config.yml index 86d240dc..6f1a61b4 100644 --- a/dev/build/config.yml +++ b/dev/build/config.yml @@ -16,4 +16,5 @@ ssl: domain: $(LETSENCRYPT_DOMAIN) subscriberEmail: $(LETSENCRYPT_EMAIL) logLevel: info +logFormat: $(LOG_FORMAT) ha: $(HA_ACTIVE) diff --git a/server/core/kernel.js b/server/core/kernel.js index 6dcb17cf..7b0303b1 100644 --- a/server/core/kernel.js +++ b/server/core/kernel.js @@ -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) } diff --git a/server/core/logger.js b/server/core/logger.js index 1902f0db..d6cf0ab5 100644 --- a/server/core/logger.js +++ b/server/core/logger.js @@ -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) diff --git a/server/modules/storage/git/storage.js b/server/modules/storage/git/storage.js index b67695dc..ee8ce503 100644 --- a/server/modules/storage/git/storage.js +++ b/server/modules/storage/git/storage.js @@ -73,7 +73,7 @@ module.exports = { mode: 0o600 }) } catch (err) { - console.error(err) + WIKI.logger.error(err) throw err } }