@@ -142,6 +142,21 @@ export class Logger {
142
142
}
143
143
}
144
144
145
+ private shouldActivateFingersCrossed ( level : LogLevel ) : boolean {
146
+ if ( ! this . fingersCrossedConfig )
147
+ return false
148
+
149
+ const levels : Record < LogLevel , number > = {
150
+ debug : 0 ,
151
+ info : 1 ,
152
+ success : 2 ,
153
+ warning : 3 ,
154
+ error : 4 ,
155
+ }
156
+ const activation = this . fingersCrossedConfig . activationLevel ?? 'error'
157
+ return levels [ level ] >= levels [ activation ]
158
+ }
159
+
145
160
private initializeFingersCrossedConfig ( options : Partial < ExtendedLoggerOptions > ) : FingersCrossedConfig | null {
146
161
if ( ! options . fingersCrossedEnabled && options . fingersCrossed ) {
147
162
return {
@@ -193,6 +208,10 @@ export class Logger {
193
208
return mergedOptions
194
209
}
195
210
211
+ private shouldWriteToFile ( ) : boolean {
212
+ return ! isBrowserProcess ( ) && this . config . writeToFile === true
213
+ }
214
+
196
215
private async writeToFile ( data : string ) : Promise < void > {
197
216
// Create a flag to track if this operation has been cancelled
198
217
const cancelled = false
@@ -380,6 +399,9 @@ export class Logger {
380
399
setupRotation ( ) : void {
381
400
if ( isBrowserProcess ( ) )
382
401
return
402
+ // Skip rotation entirely when file writing is disabled
403
+ if ( ! this . shouldWriteToFile ( ) )
404
+ return
383
405
if ( typeof this . config . rotation === 'boolean' )
384
406
return
385
407
@@ -545,6 +567,8 @@ export class Logger {
545
567
private async rotateLog ( ) : Promise < void > {
546
568
if ( isBrowserProcess ( ) )
547
569
return
570
+ if ( ! this . shouldWriteToFile ( ) )
571
+ return
548
572
549
573
const stats = await stat ( this . currentLogFile ) . catch ( ( ) => null )
550
574
if ( ! stats )
@@ -657,10 +681,11 @@ export class Logger {
657
681
if ( this . shouldActivateFingersCrossed ( level ) && ! this . isActivated ) {
658
682
this . isActivated = true
659
683
660
- // Write all buffered entries
684
+ // Write all buffered entries (to file only when enabled)
661
685
for ( const entry of this . logBuffer ) {
662
686
const formattedBufferedEntry = await this . formatter . format ( entry )
663
- await this . writeToFile ( formattedBufferedEntry )
687
+ if ( this . shouldWriteToFile ( ) )
688
+ await this . writeToFile ( formattedBufferedEntry )
664
689
// eslint-disable-next-line no-console
665
690
console . log ( formattedBufferedEntry )
666
691
}
@@ -672,41 +697,11 @@ export class Logger {
672
697
673
698
if ( this . isActivated ) {
674
699
// Direct write when activated
675
- await this . writeToFile ( formattedEntry )
700
+ if ( this . shouldWriteToFile ( ) )
701
+ await this . writeToFile ( formattedEntry )
676
702
// eslint-disable-next-line no-console
677
703
console . log ( formattedEntry )
678
704
}
679
- else {
680
- // Buffer the entry
681
- if ( this . logBuffer . length >= this . fingersCrossedConfig . bufferSize )
682
- this . logBuffer . shift ( ) // Remove oldest entry
683
-
684
- const entry : LogEntry = {
685
- timestamp : new Date ( ) ,
686
- level,
687
- message : formattedEntry ,
688
- name : this . name ,
689
- }
690
- this . logBuffer . push ( entry )
691
- }
692
- }
693
-
694
- private shouldActivateFingersCrossed ( level : LogLevel ) : boolean {
695
- if ( ! this . fingersCrossedConfig )
696
- return false
697
-
698
- return this . getLevelValue ( level ) >= this . getLevelValue ( this . fingersCrossedConfig . activationLevel )
699
- }
700
-
701
- private getLevelValue ( level : LogLevel ) : number {
702
- const levels : Record < LogLevel , number > = {
703
- debug : 0 ,
704
- info : 1 ,
705
- success : 2 ,
706
- warning : 3 ,
707
- error : 4 ,
708
- }
709
- return levels [ level ]
710
705
}
711
706
712
707
private shouldLog ( level : LogLevel ) : boolean {
@@ -1028,8 +1023,9 @@ export class Logger {
1028
1023
}
1029
1024
logEntry = logEntry . replace ( this . ANSI_PATTERN , '' )
1030
1025
1031
- // Write to file
1032
- await this . writeToFile ( logEntry )
1026
+ // Write to file only when enabled
1027
+ if ( this . shouldWriteToFile ( ) )
1028
+ await this . writeToFile ( logEntry )
1033
1029
}
1034
1030
1035
1031
/**
@@ -1090,7 +1086,8 @@ export class Logger {
1090
1086
}
1091
1087
1092
1088
// Write directly to file instead of using this.info()
1093
- await this . writeToFile ( logEntry )
1089
+ if ( this . shouldWriteToFile ( ) )
1090
+ await this . writeToFile ( logEntry )
1094
1091
}
1095
1092
}
1096
1093
@@ -1360,7 +1357,8 @@ export class Logger {
1360
1357
1361
1358
// Write directly to file instead of using this.info()
1362
1359
const logEntry = `${ fileTime } ${ this . environment } .INFO: [BOX] ${ message } \n` . replace ( this . ANSI_PATTERN , '' )
1363
- await this . writeToFile ( logEntry )
1360
+ if ( this . shouldWriteToFile ( ) )
1361
+ await this . writeToFile ( logEntry )
1364
1362
}
1365
1363
1366
1364
/**
0 commit comments