From 4b32456db7bdcbe9c8e68311fa9bbf4274188d4c Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Fri, 22 Jul 2011 12:28:02 +1000 Subject: [PATCH] fixed a bug where if the first log arg was not a string it wouldn't get logged --- lib/layouts.js | 3 +++ test/layouts.js | 14 +++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/layouts.js b/lib/layouts.js index d66daed..db212f5 100644 --- a/lib/layouts.js +++ b/lib/layouts.js @@ -41,6 +41,9 @@ function formatLogData(logData) { if (data.length > 0) { output += '\n'; } + } else { + //put it back, it's not a format string + data.unshift(format); } data.forEach(function (item) { diff --git a/test/layouts.js b/test/layouts.js index eb24fdc..0bb0a6e 100644 --- a/test/layouts.js +++ b/test/layouts.js @@ -65,7 +65,19 @@ vows.describe('log4js layouts').addBatch({ , toString: function() { return "ERROR"; } } }), "thing 1"); - } + }, + 'should output the first item even if it is not a string': function(layout) { + assert.equal(layout({ + data: [ { thing: 1} ] + , startTime: new Date(2010, 11, 5, 14, 18, 30, 45) + , categoryName: "cheese" + , level: { + colour: "green" + , toString: function() { return "ERROR"; } + } + }), "{ thing: 1 }"); + } + }, 'basicLayout': {