fixed tests broken by alwaysIncludePattern

This commit is contained in:
Gareth Jones 2013-05-05 13:44:01 +10:00
parent 097ae3d7f1
commit 936ad4da8e
4 changed files with 69 additions and 69 deletions

View File

@ -22,7 +22,7 @@ process.on('exit', function() {
function appender(filename, pattern, alwaysIncludePattern, layout) {
layout = layout || layouts.basicLayout;
var logFile = new streams.DateRollingFileStream(filename, pattern, alwaysIncludePattern);
var logFile = new streams.DateRollingFileStream(filename, pattern, { alwaysIncludePattern: alwaysIncludePattern });
openFiles.push(logFile);
return function(logEvent) {

View File

@ -13,7 +13,7 @@ if (process.env.NODE_DEBUG && /\blog4js\b/.test(process.env.NODE_DEBUG)) {
debug = function() { };
}
function DateRollingFileStream(filename, pattern, alwaysIncludePattern, options, now) {
function DateRollingFileStream(filename, pattern, options, now) {
debug("Now is " + now);
if (pattern && typeof(pattern) === 'object') {
now = options;
@ -23,12 +23,17 @@ function DateRollingFileStream(filename, pattern, alwaysIncludePattern, options,
this.pattern = pattern || '.yyyy-MM-dd';
this.now = now || Date.now;
this.lastTimeWeWroteSomething = format.asString(this.pattern, new Date(this.now()));
this.alwaysIncludePattern = alwaysIncludePattern;
if (this.alwaysIncludePattern) {
this.baseFilename = filename;
if (options) {
if (options.alwaysIncludePattern) {
filename = filename + this.lastTimeWeWroteSomething;
}
delete options.alwaysIncludePattern;
if (options === {}) {
options = null;
}
}
debug("this.now is " + this.now + ", now is " + now);
DateRollingFileStream.super_.call(this, filename, options);

View File

@ -116,17 +116,12 @@ vows.describe('../lib/appenders/dateFile').addBatch({
log4js.clearAppenders();
log4js.configure(options);
logger = log4js.getLogger('tests');
logger.warn('this should be written to the file');
return thisTime;
logger.warn('this should be written to the file with the appended date');
this.teardown = removeFile('date-file-test' + thisTime);
fs.readFile(path.join(__dirname, 'date-file-test' + thisTime), 'utf8', this.callback);
},
teardown: function(topic) {
removeFile('date-file-test' + topic);
},
'should create file with the correct pattern': function(topic) {
assert.equal(fs.existsSync(path.join(__dirname, 'date-file-test' + topic)), true);
},
'should not create file with the base filename': function(topic) {
assert.equal(fs.existsSync(path.join(__dirname, 'date-file-test')), false);
'should create file with the correct pattern': function(contents) {
assert.include(contents, 'this should be written to the file with the appended date');
}
}