changed fileappender to use writeStream instead of fs.write, tests don't work

This commit is contained in:
Gareth Jones
2011-07-17 12:28:26 +10:00
parent d64d4ca0ca
commit 3d27140a9d
2 changed files with 48 additions and 7 deletions

View File

@@ -283,16 +283,20 @@ function consoleAppender (layout) {
*/
function fileAppender (file, layout, logSize, numBackups, filePollInterval) {
layout = layout || layouts.basicLayout;
//syncs are generally bad, but we need
//the file to be open before we start doing any writing.
var logFile = fs.openSync(file, 'a', 0644);
var logFile = fs.createWriteStream(file, { flags: 'a', mode: 0644, encoding: 'utf8' });
if (logSize > 0) {
setupLogRolling(logFile, file, logSize, numBackups || 5, (filePollInterval * 1000) || 30000);
}
//close the file on process exit, otherwise the process won't die.
process.on('exit', function() {
logFile.end();
logFile.destroySoon();
});
return function(loggingEvent) {
fs.write(logFile, layout(loggingEvent)+'\n', null, "utf8");
logFile.write(layout(loggingEvent)+'\n');
};
}
@@ -312,9 +316,9 @@ function setupLogRolling (logFile, filename, logSize, numBackups, filePollInterv
}
function rollThatLog (logFile, filename, numBackups) {
//doing all of this fs stuff sync, because I don't want to lose any log events.
//first close the current one.
fs.closeSync(logFile);
logFile.end();
logFile.destroySoon();
//roll the backups (rename file.n-1 to file.n, where n <= numBackups)
for (var i=numBackups; i > 0; i--) {
if (i > 1) {
@@ -326,7 +330,7 @@ function rollThatLog (logFile, filename, numBackups) {
}
}
//open it up again
logFile = fs.openSync(filename, 'a', 0644);
logFile = fs.createWriteStream(filename, { flags: 'a', mode: 0644, encoding: "utf8" });
}
function fileExists (filename) {