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