Do not assign multiple exit
handlers for FA
This commit is contained in:
parent
3f10b68c30
commit
f832a2ba79
@ -5,6 +5,9 @@ var layouts = require('../layouts')
|
|||||||
, os = require('os')
|
, os = require('os')
|
||||||
, eol = os.EOL || '\n';
|
, eol = os.EOL || '\n';
|
||||||
|
|
||||||
|
var openFiles = [];
|
||||||
|
var listenerAtttached = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* File Appender writing the logs to a text file. Supports rolling of logs by size.
|
* File Appender writing the logs to a text file. Supports rolling of logs by size.
|
||||||
*
|
*
|
||||||
@ -42,10 +45,18 @@ function fileAppender (file, layout, logSize, numBackups) {
|
|||||||
|
|
||||||
var logFile = openTheStream(file, logSize, numBackups);
|
var logFile = openTheStream(file, logSize, numBackups);
|
||||||
|
|
||||||
|
// push file to the stack of open handlers
|
||||||
|
openFiles.push(logFile);
|
||||||
|
|
||||||
//close the file on process exit.
|
//close the file on process exit.
|
||||||
|
if (!listenerAtttached) {
|
||||||
|
listenerAtttached = true;
|
||||||
process.on('exit', function() {
|
process.on('exit', function() {
|
||||||
logFile.end();
|
openFiles.forEach(function (file) {
|
||||||
|
file.end();
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return function(loggingEvent) {
|
return function(loggingEvent) {
|
||||||
logFile.write(layout(loggingEvent) + eol, "utf8");
|
logFile.write(layout(loggingEvent) + eol, "utf8");
|
||||||
|
Loading…
Reference in New Issue
Block a user