From 8c12c948d97a9387c72088d19c9bb0dac27f23f3 Mon Sep 17 00:00:00 2001 From: Issac Goldstand Date: Wed, 8 May 2013 12:05:32 +0300 Subject: [PATCH] Fixes bug in detecting empty options (see issue #132 on github) --- lib/streams/DateRollingFileStream.js | 2 +- test/dateFileAppender-test.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/streams/DateRollingFileStream.js b/lib/streams/DateRollingFileStream.js index 0fc9394..b121f6a 100644 --- a/lib/streams/DateRollingFileStream.js +++ b/lib/streams/DateRollingFileStream.js @@ -30,7 +30,7 @@ function DateRollingFileStream(filename, pattern, options, now) { filename = filename + this.lastTimeWeWroteSomething; } delete options.alwaysIncludePattern; - if (options === {}) { + if (Object.keys(options).length === 0) { options = null; } } diff --git a/test/dateFileAppender-test.js b/test/dateFileAppender-test.js index 6b8b047..01433e7 100644 --- a/test/dateFileAppender-test.js +++ b/test/dateFileAppender-test.js @@ -113,6 +113,7 @@ vows.describe('../lib/appenders/dateFile').addBatch({ ] } , thisTime = format.asString(options.appenders[0].pattern, new Date()); + fs.writeFileSync(path.join(__dirname, 'date-file-test' + thisTime), "this is existing data" + require('os').EOL, 'utf8'); log4js.clearAppenders(); log4js.configure(options); logger = log4js.getLogger('tests'); @@ -122,6 +123,9 @@ vows.describe('../lib/appenders/dateFile').addBatch({ }, 'should create file with the correct pattern': function(contents) { assert.include(contents, 'this should be written to the file with the appended date'); + }, + 'should not overwrite the file on open (bug found in issue #132)': function(contents) { + assert.include(contents, 'this is existing data'); } }