Skip to content

Commit d761960

Browse files
committed
Fix logging regular expression objects
1 parent 9142c94 commit d761960

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

examples/regular-expressions.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
var winston = require('../');
2+
3+
console.info(new RegExp('a'));
4+
// prints "/a/"
5+
6+
winston.info(new RegExp('a'));
7+
// prints "info: /a/"

lib/winston/logger.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ Logger.prototype.log = function (level) {
124124
}
125125

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

130130
// If we should pad for levels, do so

test/logger-test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,17 @@ vows.describe('winton/logger').addBatch({
356356
assert.strictEqual(msg, 'test message first second');
357357
assert.deepEqual(meta, {number: 123});
358358
},
359+
},
360+
"when passed a regular expression": {
361+
topic: function (logger) {
362+
var that = this;
363+
logger.log('info', new RegExp('a'), function(transport, level, msg, meta){
364+
that.callback(transport, level, msg, meta)
365+
});
366+
},
367+
"should return a string representing the regular expression": function (transport, level, msg, meta) {
368+
assert.strictEqual(msg, '/a/');
369+
},
359370
}
360371
}
361372
}

0 commit comments

Comments
 (0)