8000 Do not assign multiple `exit` handlers for FA · rboss/log4js-node@f832a2b · GitHub
[go: up one dir, main page]

Skip to content

Commit f832a2b

Browse files
committed
Do not assign multiple exit handlers for FA
1 parent 3f10b68 commit f832a2b

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

lib/appenders/file.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ var layouts = require('../layouts')
55
, os = require('os')
66
, eol = os.EOL || '\n';
77

8+
var openFiles = [];
9+
var listenerAtttached = false;
10+
811
/**
912
* File Appender writing the logs to a text file. Supports rolling of logs by size.
1013
*
@@ -42,10 +45,18 @@ function fileAppender (file, layout, logSize, numBackups) {
4245

4346
var logFile = openTheStream(file, logSize, numBackups);
4447

48+
// push file to the stack of open handlers
49+
openFiles.push(logFile);
50+
4551
//close the file on process exit.
46-
process.on('exit', function() {
47-
logFile.end();
48-
});
52+
if (!listenerAtttached) {
53+
listenerAtttached = true;
54+
process.on('exit', function() {
55+
openFiles.forEach(function (file) {
56+
file.end();
57+
});
58+
});
59+
}
4960

5061
return function(loggingEvent) {
5162
logFile.write(layout(loggingEvent) + eol, "utf8");

0 commit comments

Comments
 (0)
0