Skip to content

Commit

Permalink
Fix logging regular expression objects
Browse files Browse the repository at this point in the history
  • Loading branch information
chasenlehara committed Dec 15, 2014
1 parent 9142c94 commit d761960
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
7 changes: 7 additions & 0 deletions examples/regular-expressions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var winston = require('../');

console.info(new RegExp('a'));
// prints "/a/"

winston.info(new RegExp('a'));
// prints "info: /a/"
2 changes: 1 addition & 1 deletion lib/winston/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ Logger.prototype.log = function (level) {
}

var callback = typeof args[args.length - 1] === 'function' ? args.pop() : null,
meta = typeof args[args.length - 1] === 'object' ? args.pop() : {},
meta = typeof args[args.length - 1] === 'object' && Object.prototype.toString.call(args[args.length - 1]) !== '[object RegExp]' ? args.pop() : {},
msg = util.format.apply(null, args);

// If we should pad for levels, do so
Expand Down
11 changes: 11 additions & 0 deletions test/logger-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,17 @@ vows.describe('winton/logger').addBatch({
assert.strictEqual(msg, 'test message first second');
assert.deepEqual(meta, {number: 123});
},
},
"when passed a regular expression": {
topic: function (logger) {
var that = this;
logger.log('info', new RegExp('a'), function(transport, level, msg, meta){
that.callback(transport, level, msg, meta)
});
},
"should return a string representing the regular expression": function (transport, level, msg, meta) {
assert.strictEqual(msg, '/a/');
},
}
}
}
Expand Down

0 comments on commit d761960

Please sign in to comment.