8000 Refactored where the exit handler gets added · Web5design/log4js-node@9ac61e3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9ac61e3

Browse files
author
Gareth Jones
committed
Refactored where the exit handler gets added
1 parent 185f343 commit 9ac61e3

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

lib/appenders/file.js

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
var layouts = require('../layouts')
2-
, path = require('path')
3-
, fs = require('fs')
4-
, streams = require('../streams')
5-
, os = require('os')
6-
, eol = os.EOL || '\n';
2+
, path = require('path')
3+
, fs = require('fs')
4+
, streams = require('../streams')
5+
, os = require('os')
6+
, eol = os.EOL || '\n'
7+
, openFiles = [];
78

8-
var openFiles = [];
9-
var listenerAtttached = false;
9+
//close open files on process exit.
10+
process.on('exit', function() {
11+
openFiles.forEach(function (file) {
12+
file.end();
13+
});
14+
});
1015

1116
/**
1217
* 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) {
4853
// push file to the stack of open handlers
4954
openFiles.push(logFile);
5055

51-
//close the file on process exit.
52-
if (!listenerAtttached) {
53-
listenerAtttached = true;
54-
process.on('exit', function() {
55-
openFiles.forEach(function (file) {
56-
file.end();
57-
});
58-
});
59-
}
60-
6156
return function(loggingEvent) {
6257
logFile.write(layout(loggingEvent) + eol, "utf8");
6358
};

0 commit comments

Comments
 (0)
0