From 1f16861b0382e2880b706876728de5f445405f6c Mon Sep 17 00:00:00 2001 From: indexzero Date: Mon, 2 Nov 2015 23:34:33 -0800 Subject: [PATCH] [fix] Ensure that `logger.log("info", undefined)` does not throw. Fixes #739. --- lib/winston/logger.js | 2 +- test/logger-test.js | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/winston/logger.js b/lib/winston/logger.js index 130a8aba1..97fba6428 100755 --- a/lib/winston/logger.js +++ b/lib/winston/logger.js @@ -166,7 +166,7 @@ Logger.prototype.log = function (level) { // logger.info('No interpolation symbols', 'ok', 'why', { meta: 'is-this' }); // var metaType = Object.prototype.toString.call(args[args.length - 1]), - fmtMatch = args[0].match && args[0].match(formatRegExp), + fmtMatch = args[0] && args[0].match && args[0].match(formatRegExp), isFormat = fmtMatch && fmtMatch.length, validMeta = !isFormat ? metaType === '[object Object]' || metaType === '[object Error]' || metaType === '[object Array]' diff --git a/test/logger-test.js b/test/logger-test.js index bc3773441..d85f7be4d 100755 --- a/test/logger-test.js +++ b/test/logger-test.js @@ -281,6 +281,9 @@ vows.describe('winton/logger').addBatch({ ] }), "the log() method": { + "when passed undefined should not throw": function (logger) { + assert.doesNotThrow(function () { logger.log('info', undefined) }); + }, "when passed an Error object as meta": { topic: function (logger) { logger.once('logging', this.callback);