fixed tests broken by alwaysIncludePattern

isaacg-alwaysIncludePattern
Gareth Jones 12 years ago
parent 097ae3d7f1
commit 936ad4da8e

@ -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) {

@ -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);

@ -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;
},
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);
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);
},
'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');
}
}

Loading…
Cancel
Save