fixed log rolling problem

This commit is contained in:
Gareth Jones 2011-07-21 20:42:14 +10:00
parent 925c280c68
commit a9a698cf09
2 changed files with 3 additions and 22 deletions

View File

@ -295,12 +295,6 @@ function fileAppender (file, layout, logSize, numBackups, filePollInterval) {
//close the file on process exit. //close the file on process exit.
process.on('exit', function() { process.on('exit', function() {
logFile.end(); logFile.end();
//node v0.2.x does not have destroySoon
if (logFile.destroySoon) {
logFile.destroySoon();
} else {
logFile.destroy();
}
}); });
return function(loggingEvent) { return function(loggingEvent) {
@ -326,11 +320,6 @@ function setupLogRolling (logFile, filename, logSize, numBackups, filePollInterv
function rollThatLog (logFile, filename, numBackups) { function rollThatLog (logFile, filename, numBackups) {
//first close the current one. //first close the current one.
logFile.end(); logFile.end();
if (logFile.destroySoon) {
logFile.destroySoon();
} else {
logFile.destroy();
}
//roll the backups (rename file.n-1 to file.n, where n <= numBackups) //roll the backups (rename file.n-1 to file.n, where n <= numBackups)
for (var i=numBackups; i > 0; i--) { for (var i=numBackups; i > 0; i--) {
if (i > 1) { if (i > 1) {

View File

@ -108,7 +108,6 @@ vows.describe('log4js').addBatch({
var watchCb, var watchCb,
filesOpened = [], filesOpened = [],
filesEnded = [], filesEnded = [],
filesDestroyedSoon = [],
filesRenamed = [], filesRenamed = [],
newFilenames = [], newFilenames = [],
existingFiles = ['tests.log'], existingFiles = ['tests.log'],
@ -130,9 +129,6 @@ vows.describe('log4js').addBatch({
return { return {
end: function() { end: function() {
filesEnded.push(file); filesEnded.push(file);
},
destroySoon: function() {
filesDestroyedSoon.push(file);
} }
}; };
}, },
@ -152,16 +148,15 @@ vows.describe('log4js').addBatch({
} }
); );
var appender = log4js.fileAppender('tests.log', log4js.messagePassThroughLayout, 1024, 2, 30); var appender = log4js.fileAppender('tests.log', log4js.messagePassThroughLayout, 1024, 2, 30);
return [watchCb, filesOpened, filesEnded, filesDestroyedSoon, filesRenamed, existingFiles]; return [watchCb, filesOpened, filesEnded, filesRenamed, existingFiles];
}, },
'should close current log file, rename all old ones, open new one on rollover': function(args) { 'should close current log file, rename all old ones, open new one on rollover': function(args) {
var watchCb = args[0] var watchCb = args[0]
, filesOpened = args[1] , filesOpened = args[1]
, filesEnded = args[2] , filesEnded = args[2]
, filesDestroyedSoon = args[3] , filesRenamed = args[3]
, filesRenamed = args[4] , existingFiles = args[4];
, existingFiles = args[5];
assert.isFunction(watchCb); assert.isFunction(watchCb);
//tell the watchCb that the file is below the threshold //tell the watchCb that the file is below the threshold
watchCb({ size: 891 }, { size: 0 }); watchCb({ size: 891 }, { size: 0 });
@ -171,7 +166,6 @@ vows.describe('log4js').addBatch({
watchCb({ size: 1053 }, { size: 891 }); watchCb({ size: 1053 }, { size: 891 });
//it should have closed the first log file. //it should have closed the first log file.
assert.length(filesEnded, 1); assert.length(filesEnded, 1);
assert.length(filesDestroyedSoon, 1);
//it should have renamed the previous log file //it should have renamed the previous log file
assert.length(filesRenamed, 1); assert.length(filesRenamed, 1);
//and we should have two files now //and we should have two files now
@ -184,7 +178,6 @@ vows.describe('log4js').addBatch({
watchCb({ size: 1025 }, { size: 123 }); watchCb({ size: 1025 }, { size: 123 });
//it should have closed the old file //it should have closed the old file
assert.length(filesEnded, 2); assert.length(filesEnded, 2);
assert.length(filesDestroyedSoon, 2);
//it should have renamed both the old log file, and the previous '.1' file //it should have renamed both the old log file, and the previous '.1' file
assert.length(filesRenamed, 3); assert.length(filesRenamed, 3);
assert.deepEqual(filesRenamed, ['tests.log', 'tests.log.1', 'tests.log' ]); assert.deepEqual(filesRenamed, ['tests.log', 'tests.log.1', 'tests.log' ]);
@ -198,7 +191,6 @@ vows.describe('log4js').addBatch({
watchCb({ size: 1024 }, { size: 234 }); watchCb({ size: 1024 }, { size: 234 });
//close the old one again. //close the old one again.
assert.length(filesEnded, 3); assert.length(filesEnded, 3);
assert.length(filesDestroyedSoon, 3);
//it should have renamed the old log file and the 2 backups, with the last one being overwritten. //it should have renamed the old log file and the 2 backups, with the last one being overwritten.
assert.length(filesRenamed, 5); assert.length(filesRenamed, 5);
assert.deepEqual(filesRenamed, ['tests.log', 'tests.log.1', 'tests.log', 'tests.log.1', 'tests.log' ]); assert.deepEqual(filesRenamed, ['tests.log', 'tests.log.1', 'tests.log', 'tests.log.1', 'tests.log' ]);