diff --git a/examples/regular-expressions.js b/examples/regular-expressions.js new file mode 100644 index 000000000..8f7887368 --- /dev/null +++ b/examples/regular-expressions.js @@ -0,0 +1,7 @@ +var winston = require('../'); + +console.info(new RegExp('a')); +// prints "/a/" + +winston.info(new RegExp('a')); +// prints "info: /a/" \ No newline at end of file diff --git a/lib/winston/logger.js b/lib/winston/logger.js index 5934e9e42..b6f188354 100755 --- a/lib/winston/logger.js +++ b/lib/winston/logger.js @@ -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 diff --git a/test/logger-test.js b/test/logger-test.js index 2f3079c0c..7501755c7 100755 --- a/test/logger-test.js +++ b/test/logger-test.js @@ -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/'); + }, } } }