Skip to content

Commit

Permalink
feat(logging): Add logging-setup function
Browse files Browse the repository at this point in the history
Add a setup-function for setting up the log-level and colors from config.
  • Loading branch information
budde377 committed Feb 21, 2016
1 parent 414db89 commit d14bd62
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -60,3 +83,4 @@ var create = function (name, level) {

exports.create = create
exports.setup = setup
exports.setupFromConfig = setupFromConfig

0 comments on commit d14bd62

Please sign in to comment.