From c3584770f24205d84b9399abd9535cb27dc7b00c Mon Sep 17 00:00:00 2001 From: Sheogorath Date: Tue, 13 Nov 2018 23:29:33 +0100 Subject: Upgrade winston Our log library got a new major version which should be implemented. That's exactly what this patch does. Implementing the new version of the logging library. Signed-off-by: Sheogorath --- lib/config/default.js | 1 + lib/config/environment.js | 1 + lib/config/index.js | 6 ++++++ lib/logger.js | 28 ++++++++++++---------------- 4 files changed, 20 insertions(+), 16 deletions(-) (limited to 'lib') diff --git a/lib/config/default.js b/lib/config/default.js index 15f11aaa..71375b98 100644 --- a/lib/config/default.js +++ b/lib/config/default.js @@ -7,6 +7,7 @@ module.exports = { urlPath: '', host: '0.0.0.0', port: 3000, + loglevel: 'info', urlAddPort: false, allowOrigin: ['localhost'], useSSL: false, diff --git a/lib/config/environment.js b/lib/config/environment.js index 0c7c9a4f..4220e54d 100644 --- a/lib/config/environment.js +++ b/lib/config/environment.js @@ -9,6 +9,7 @@ module.exports = { host: process.env.CMD_HOST, port: toIntegerConfig(process.env.CMD_PORT), path: process.env.CMD_PATH, + loglevel: process.env.CMD_LOGLEVEL, urlAddPort: toBooleanConfig(process.env.CMD_URL_ADDPORT), useSSL: toBooleanConfig(process.env.CMD_USESSL), hsts: { diff --git a/lib/config/index.js b/lib/config/index.js index 4e1fa50d..c1005b0b 100644 --- a/lib/config/index.js +++ b/lib/config/index.js @@ -45,6 +45,12 @@ merge(config, require('./hackmdEnvironment')) merge(config, require('./environment')) merge(config, require('./dockerSecret')) +if (['debug', 'verbose', 'info', 'warn', 'error'].includes(config.loglevel)) { + logger.level = config.loglevel +} else { + logger.error('Selected loglevel %s doesn\'t exist, using default level \'debug\'. Available options: debug, verbose, info, warn, error', config.loglevel) +} + // load LDAP CA if (config.ldap.tlsca) { let ca = config.ldap.tlsca.split(',') diff --git a/lib/logger.js b/lib/logger.js index f8b3895c..c70b81b8 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -1,23 +1,19 @@ 'use strict' -const winston = require('winston') +const {createLogger, format, transports} = require('winston') -class Logger extends winston.Logger { - // Implement stream.writable.write interface - write (chunk) { - this.info(chunk) - } -} - -module.exports = new Logger({ +module.exports = createLogger({ + level: 'debug', + format: format.combine( + format.uncolorize(), + format.timestamp(), + format.align(), + format.splat(), + format.printf(info => `${info.timestamp} ${info.level}: ${info.message}`) + ), transports: [ - new winston.transports.Console({ - level: 'debug', - handleExceptions: true, - json: false, - colorize: false, - timestamp: true + new transports.Console({ + handleExceptions: true }) ], - emitErrs: true, exitOnError: false }) -- cgit v1.2.3