From d14bd62b14a1e42d3a24be848916f5defe5a7e84 Mon Sep 17 00:00:00 2001 From: Christian Budde Christensen Date: Sun, 21 Feb 2016 10:56:07 +0100 Subject: [PATCH] feat(logging): Add logging-setup function Add a setup-function for setting up the log-level and colors from config. --- lib/logger.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/logger.js b/lib/logger.js index 455081dbe..210242996 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -43,6 +43,29 @@ var setup = function (level, colors, appenders) { }) } +// Setup the logger by passing in the config object. The function sets the +// `colors` and `logLevel` if they are defined. It takes two arguments: +// +// setupFromConfig(config, appenders) +// +// * `config`: *Object* The configuration object. +// * `appenders`: *Array* This will be passed as appenders to log4js +// to allow for fine grained configuration of log4js. For more information +// see https://github.com/nomiddlename/log4js-node. +var setupFromConfig = function (config, appenders) { + var useColors = true + var logLevel = constant.LOG_INFO + + if (helper.isDefined(config.colors)) { + useColors = config.colors + } + + if (helper.isDefined(config.logLevel)) { + logLevel = config.logLevel + } + setup(logLevel, useColors, appenders) +} + // Create a new logger. There are two optional arguments // * `name`, which defaults to `karma` and // If the `name = 'socket.io'` this will create a special wrapper @@ -60,3 +83,4 @@ var create = function (name, level) { exports.create = create exports.setup = setup +exports.setupFromConfig = setupFromConfig