@@ -11,17 +11,19 @@ var debug = require('debug')('log4js:file')
11
11
12
12
//close open files on process exit.
13
13
process . on ( 'exit' , function ( ) {
14
+ debug ( 'Exit handler called.' ) ;
14
15
openFiles . forEach ( function ( file ) {
15
- file . stream . end ( ) ;
16
+ file . end ( ) ;
16
17
} ) ;
17
18
} ) ;
18
19
19
20
// On SIGHUP, close and reopen all files. This allows this appender to work with
20
21
// logrotate. Note that if you are using logrotate, you should not set
21
22
// `logSize`.
22
23
process . on ( 'SIGHUP' , function ( ) {
24
+ debug ( 'SIGHUP handler called.' ) ;
23
25
openFiles . forEach ( function ( writer ) {
24
- writer . reopen ( ) ;
26
+ writer . closeTheStream ( writer . openTheStream . bind ( writer ) ) ;
25
27
} ) ;
26
28
} ) ;
27
29
@@ -39,27 +41,20 @@ process.on('SIGHUP', function() {
39
41
* @param timezoneOffset - optional timezone offset in minutes (default system local)
40
42
*/
41
43
function fileAppender ( file , layout , logSize , numBackups , options , timezoneOffset ) {
42
- var bytesWritten = 0 ;
43
44
file = path . normalize ( file ) ;
44
45
layout = layout || layouts . basicLayout ;
45
46
numBackups = numBackups === undefined ? 5 : numBackups ;
46
47
//there has to be at least one backup if logSize has been specified
47
48
numBackups = numBackups === 0 ? 1 : numBackups ;
48
49
49
50
debug ( "Creating file appender (" , file , ", " , logSize , ", " , numBackups , ", " , options , ")" ) ;
50
- var writer = {
51
- stream : openTheStream ( file , logSize , numBackups , options ) ,
52
- reopen : function ( ) {
53
- this . stream . end ( ) ;
54
- this . stream = openTheStream ( file , logSize , numBackups , options ) ;
55
- }
56
- } ;
51
+ var writer = openTheStream ( file , logSize , numBackups ,
10000
options ) ;
57
52
58
53
// push file to the stack of open handlers
59
54
openFiles . push ( writer ) ;
60
55
61
56
return function ( loggingEvent ) {
62
- writer . stream . write ( layout ( loggingEvent , timezoneOffset ) + eol , "utf8" ) ;
57
+ writer . write ( layout ( loggingEvent , timezoneOffset ) + eol , "utf8" ) ;
63
58
} ;
64
59
65
60
}
@@ -112,7 +107,7 @@ function shutdown(cb) {
112
107
return cb ( ) ;
113
108
}
114
109
openFiles . forEach ( function ( file ) {
115
- var stream = file . stream ;
110
+ var stream = file ;
116
111
if ( ! stream . write ( eol , "utf-8" ) ) {
117
112
stream . once ( 'drain' , function ( ) {
118
113
stream . end ( complete ) ;
0 commit comments