fixed the behaviour of maxlogsize + 0 backups
This commit is contained in:
@@ -13,6 +13,8 @@ var layouts = require('../layouts')
|
||||
function fileAppender (file, layout, logSize, numBackups, filePollInterval) {
|
||||
layout = layout || layouts.basicLayout;
|
||||
numBackups = numBackups === undefined ? 5 : numBackups;
|
||||
//there has to be at least one backup if logSize has been specified
|
||||
numBackups = numBackups === 0 ? 1 : numBackups;
|
||||
filePollInterval = filePollInterval * 1000 || 30000;
|
||||
|
||||
function setupLogRolling () {
|
||||
@@ -31,25 +33,21 @@ function fileAppender (file, layout, logSize, numBackups, filePollInterval) {
|
||||
}
|
||||
|
||||
function rollThatLog () {
|
||||
if (numBackups > 0) {
|
||||
//roll the backups (rename file.n-1 to file.n, where n <= numBackups)
|
||||
for (var i=numBackups; i > 0; i--) {
|
||||
if (i > 1) {
|
||||
if (fileExists(file + '.' + (i-1))) {
|
||||
fs.renameSync(file+'.'+(i-1), file+'.'+i);
|
||||
}
|
||||
} else {
|
||||
fs.renameSync(file, file+'.1');
|
||||
//roll the backups (rename file.n-1 to file.n, where n <= numBackups)
|
||||
for (var i=numBackups; i > 0; i--) {
|
||||
if (i > 1) {
|
||||
if (fileExists(file + '.' + (i-1))) {
|
||||
fs.renameSync(file+'.'+(i-1), file+'.'+i);
|
||||
}
|
||||
} else {
|
||||
fs.renameSync(file, file+'.1');
|
||||
}
|
||||
//let's make a new file
|
||||
var newLogFileFD = fs.openSync(file, 'a', 0644)
|
||||
, oldLogFileFD = logFile.fd;
|
||||
logFile.fd = newLogFileFD;
|
||||
fs.close(oldLogFileFD);
|
||||
} else {
|
||||
fs.truncate(logFile.fd, logSize);
|
||||
}
|
||||
//let's make a new file
|
||||
var newLogFileFD = fs.openSync(file, 'a', 0644)
|
||||
, oldLogFileFD = logFile.fd;
|
||||
logFile.fd = newLogFileFD;
|
||||
fs.close(oldLogFileFD);
|
||||
}
|
||||
|
||||
function fileExists (filename) {
|
||||
|
||||
@@ -159,7 +159,9 @@ function configureLevels(levels) {
|
||||
}
|
||||
} else {
|
||||
for (l in loggers) {
|
||||
loggers[l].setLevel();
|
||||
if (loggers.hasOwnProperty(l)) {
|
||||
loggers[l].setLevel();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user