@@ -19,6 +19,8 @@ export const defaultLogFile = 'z-ui_%DATE%.log'
19
19
20
20
export const disableColors = process . env . NO_LOG_COLORS === 'true'
21
21
22
+ let fileTransport : winston . transport = null
23
+
22
24
// ensure store and logs directories exist
23
25
ensureDirSync ( storeDir )
24
26
ensureDirSync ( logsDir )
@@ -130,31 +132,33 @@ export function customTransports(config: LoggerConfig): winston.transport[] {
130
132
transportsList . push ( streamTransport )
131
133
132
134
if ( config . logToFile ) {
133
- let fileTransport : winston . transport
134
- if ( process . env . DISABLE_LOG_ROTATION === 'true' ) {
135
- fileTransport = new transports . File ( {
136
- format : customFormat ( config , true ) ,
137
- filename : config . filePath ,
138
- level : config . level ,
139
- } )
140
- } else {
141
- const options : DailyRotateFileTransportOptions = {
142
- filename : config . filePath ,
143
- auditFile : joinPath ( logsDir , 'zui-logs.audit.json' ) ,
144
- datePattern : 'YYYY-MM-DD' ,
145
- createSymlink : true ,
146
- symlinkName : path
147
- . basename ( config . filePath )
148
- . replace ( `_%DATE%` , '_current' ) ,
149
- zippedArchive : true ,
150
- maxFiles : process . env . ZUI_LOG_MAXFILES || '7d' ,
151
- maxSize : process . env . ZUI_LOG_MAXSIZE || '50m' ,
152
- level : config . level ,
153
- format : customFormat ( config , true ) ,
154
- }
155
- fileTransport = new DailyRotateFile ( options )
135
+ // setup file transport only once (see issue #2937)
136
+ if ( ! fileTransport ) {
137
+ if ( process . env . DISABLE_LOG_ROTATION === 'true' ) {
138
+ fileTransport = new transports . File ( {
139
+ format : customFormat ( config , true ) ,
140
+ filename : config . filePath ,
141
+ level : config . level ,
142
+ } )
143
+ } else {
144
+ const options : DailyRotateFileTransportOptions = {
145
+ filename : config . filePath ,
146
+ auditFile : joinPath ( logsDir , 'zui-logs.audit.json' ) ,
147
+ datePattern : 'YYYY-MM-DD' ,
148
+ createSymlink : true ,
149
+ symlinkName : path
150
+ . basename ( config . filePath )
151
+ . replace ( `_%DATE%` , '_current' ) ,
152
+ zippedArchive : true ,
153
+ maxFiles : process . env . ZUI_LOG_MAXFILES || '7d' ,
154
+ maxSize : process . env . ZUI_LOG_MAXSIZE || '50m' ,
155
+ level : config . level ,
156
+ format : customFormat ( config , true ) ,
157
+ }
158
+ fileTransport = new DailyRotateFile ( options )
156
159
157
- setupCleanJob ( options )
160
+ setupCleanJob ( options )
161
+ }
158
162
}
159
163
160
164
transportsList . push ( fileTransport )
@@ -199,6 +203,10 @@ export function module(module: string): ModuleLogger {
199
203
export function setupAll ( config : DeepPartial < GatewayConfig > ) {
200
204
stopCleanJob ( )
201
205
206
+ fileTransport . close ( )
207
+
208
+ fileTransport = null
209
+
202
210
logContainer . loggers . forEach ( ( logger : ModuleLogger ) => {
203
211
logger . setup ( config )
204
212
} )
0 commit comments