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) { function appender(filename, pattern, alwaysIncludePattern, layout) {
layout = layout || layouts.basicLayout; layout = layout || layouts.basicLayout;
var logFile = new streams.DateRollingFileStream(filename, pattern, alwaysIncludePattern); var logFile = new streams.DateRollingFileStream(filename, pattern, { alwaysIncludePattern: alwaysIncludePattern });
openFiles.push(logFile); openFiles.push(logFile);
return function(logEvent) { return function(logEvent) {

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

@ -116,17 +116,12 @@ vows.describe('../lib/appenders/dateFile').addBatch({
log4js.clearAppenders(); log4js.clearAppenders();
log4js.configure(options); log4js.configure(options);
logger = log4js.getLogger('tests'); logger = log4js.getLogger('tests');
logger.warn('this should be written to the file'); logger.warn('this should be written to the file with the appended date');
return thisTime; 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) { 'should create file with the correct pattern': function(contents) {
assert.equal(fs.existsSync(path.join(__dirname, 'date-file-test')), false); assert.include(contents, 'this should be written to the file with the appended date');
} }
} }

Loading…
Cancel
Save