Refactored where the exit handler gets added

date-rolling-file-appender
Gareth Jones 12 years ago
parent 185f343e68
commit 9ac61e37f4

@ -1,12 +1,17 @@
var layouts = require('../layouts')
, path = require('path')
, fs = require('fs')
, streams = require('../streams')
, os = require('os')
, eol = os.EOL || '\n';
, path = require('path')
, fs = require('fs')
, streams = require('../streams')
, os = require('os')
, eol = os.EOL || '\n'
, openFiles = [];
var openFiles = [];
var listenerAtttached = false;
//close open files on process exit.
process.on('exit', function() {
openFiles.forEach(function (file) {
file.end();
});
});
/**
* File Appender writing the logs to a text file. Supports rolling of logs by size.
@ -48,16 +53,6 @@ function fileAppender (file, layout, logSize, numBackups) {
// push file to the stack of open handlers
openFiles.push(logFile);
//close the file on process exit.
if (!listenerAtttached) {
listenerAtttached = true;
process.on('exit', function() {
openFiles.forEach(function (file) {
file.end();
});
});
}
return function(loggingEvent) {
logFile.write(layout(loggingEvent) + eol, "utf8");
};

Loading…
Cancel
Save