1
1
"use strict" ;
2
- var layouts = require ( '../layouts' )
2
+ var debug = require ( 'debug' ) ( 'log4js:file' )
3
+ , layouts = require ( '../layouts' )
3
4
, path = require ( 'path' )
4
5
, fs = require ( 'fs' )
5
6
, streams = require ( 'streamroller' )
@@ -34,24 +35,25 @@ process.on('SIGHUP', function() {
34
35
* if not provided then logs won't be rotated.
35
36
* @param numBackups - the number of log files to keep after logSize
36
37
* has been reached (default 5)
37
- * @param compress - flag that controls log file compression
38
+ * @param options - options to be passed to the underlying stream
38
39
* @param timezoneOffset - optional timezone offset in minutes (default system local)
39
40
*/
40
- function fileAppender ( file , layout , logSize , numBackups , compress , timezoneOffset ) {
41
+ function fileAppender ( file , layout , logSize , numBackups , options , timezoneOffset ) {
41
42
var bytesWritten = 0 ;
42
43
file = path . normalize ( file ) ;
43
44
layout = layout || layouts . basicLayout ;
44
45
numBackups = numBackups === undefined ? 5 : numBackups ;
45
46
//there has to be at least one backup if logSize has been specified
46
47
numBackups = numBackups === 0 ? 1 : numBackups ;
47
48
49
+ debug ( "Creating file appender (" , file , ", " , logSize , ", " , numBackups , ", " , options , ")" ) ;
48
50
var writer = {
49
- stream : openTheStream ( file , logSize , numBackups ) ,
51
+ stream : openTheStream ( file , logSize , numBackups , options ) ,
50
52
reopen : function ( ) {
51
53
this . stream . end ( ) ;
52
- this . stream = openTheStream ( file , logSize , numBackups ) ;
54
+ this . stream = openTheStream ( file , logSize , numBackups , options ) ;
53
55
}
54
- }
56
+ } ;
55
57
56
58
// push file to the stack of open handlers
57
59
openFiles . push ( writer ) ;
@@ -62,23 +64,13 @@ function fileAppender (file, layout, logSize, numBackups, compress, timezoneOffs
62
64
63
65
}
64
66
65
- function openTheStream ( file , fileSize , numFiles ) {
66
- var stream ;
67
- if ( fileSize ) {
68
- stream = new streams . RollingFileStream (
69
- file ,
70
- fileSize ,
71
- numFiles ,
72
- { "compress" : compress }
73
- ) ;
74
- } else {
75
- stream = fs . createWriteStream (
76
- file ,
77
- { encoding : "utf8" ,
78
- mode : parseInt ( '0644' , 8 ) ,
79
- flags : 'a' }
80
- ) ;
81
- }
67
+ function openTheStream ( file , fileSize , numFiles , options ) {
68
+ var stream = new streams . RollingFileStream (
69
+ file ,
70
+ fileSize ,
71
+ numFiles ,
72
+ options
73
+ ) ;
82
74
stream . on ( "error" , function ( err ) {
83
75
console . error ( "log4js.fileAppender - Writing to file %s, error happened " , file , err ) ;
84
76
} ) ;
@@ -101,8 +93,8 @@ function configure(config, options) {
101
93
layout ,
102
94
config . maxLogSize ,
103
95
config . backups ,
104
- config . compress ,
105
- config . timezoneOffset
96
+ config . timezoneOffset ,
97
+ config
106
98
) ;
107
99
}
108
100
0 commit comments