diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..5794f61 --- /dev/null +++ b/.jshintrc @@ -0,0 +1,6 @@ +{ + "node": true, + "laxcomma": true, + "sub": true, + "expr": true +} diff --git a/README.md b/README.md index a0b88ab..64e13a3 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ # CLogger # -A [node.js](http://nodejs.org) module with various configurable and +A [node.js](http://nodejs.org) logging module with various configurable and extendable transports. As per default, the **CLogger** prints its colored messages to the node-console, but it can be configured to logs to a [TaffyDB](http://www.taffydb.com) instance, a log-file diff --git a/lib/clogger.js b/lib/clogger.js index 84edff1..959c619 100644 --- a/lib/clogger.js +++ b/lib/clogger.js @@ -9,7 +9,8 @@ var _ = require('lodash') * @param {string} id (optional) - An internal identifier. * @param {object} opts (optional) - An object, holding options to configure the logger instance. * At the moment, the only configurable options, are an array of transports to be used and an - * array of visible log-levels. + * array of visible log-levels. Log-levels can be given as environment-variables in the form of + * 'VISIBLE=info,warn,error node app.js'. * @example * var clogger = require('node-clogger'); * var logger = new clogger.CLogger('server', { @@ -23,7 +24,7 @@ var _ = require('lodash') function CLogger(id, opts) { if (arguments.length === 1 && _.isPlainObject(id)) { config = id; - id = 'default' + id = 'default'; } this.id = id || 'default'; @@ -40,7 +41,7 @@ function CLogger(id, opts) { 'debug', 'error' ] - }).load(opts || {}); + }).load(opts || {}).parseEnv(); } /** @@ -77,7 +78,7 @@ CLogger.prototype.log = function(level, message) { var args = _.toArray(arguments).slice(2) , visible = this.config.getValue('visible'); - if (visible.indexOf(level) > -1) { + if ((_.isString(visible) && visible === level) || (_.isArray(visible) && _.indexOf(visible, level) > -1)) { var timestamp = new Date().getTime(); message = util.format.apply(null, [message].concat(args)); @@ -163,6 +164,6 @@ CLogger.prototype.extend = function(obj) { } else { throw new TypeError('CLogger extends only "objects"!'); } -} +}; module.exports = CLogger; diff --git a/test/clogger.spec.js b/test/clogger.spec.js index b8f3c68..dd221b9 100644 --- a/test/clogger.spec.js +++ b/test/clogger.spec.js @@ -48,7 +48,7 @@ describe('CLogger', function() { logger.warn('dlc'); logger.debug('dlc'); - logger.config.getValue('visible').push('trace'); + logger.config.getValue('visible', ['info', 'warn', 'trace']); logger.trace('dlc'); }); });