Skip to content

Commit

Permalink
Add environment parser.
Browse files Browse the repository at this point in the history
  • Loading branch information
incredible-io committed Aug 21, 2014
1 parent bc568f2 commit 303166e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
6 changes: 6 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"node": true,
"laxcomma": true,
"sub": true,
"expr": true
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions lib/clogger.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand All @@ -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';
Expand All @@ -40,7 +41,7 @@ function CLogger(id, opts) {
'debug',
'error'
]
}).load(opts || {});
}).load(opts || {}).parseEnv();
}

/**
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -163,6 +164,6 @@ CLogger.prototype.extend = function(obj) {
} else {
throw new TypeError('CLogger extends only "objects"!');
}
}
};

module.exports = CLogger;
2 changes: 1 addition & 1 deletion test/clogger.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
Expand Down

0 comments on commit 303166e

Please sign in to comment.