@@ -125,6 +125,8 @@ class Logger extends Utility implements ClassThatLogs {
125
125
126
126
private logFormatter ?: LogFormatterInterface ;
127
127
128
+ private logIndentation : number = LogJsonIndent . COMPACT ;
129
+
128
130
private logLevel ?: LogLevel ;
129
131
130
132
private readonly logLevelThresholds : LogLevelThresholds = {
@@ -570,10 +572,7 @@ class Logger extends Utility implements ClassThatLogs {
570
572
571
573
const consoleMethod = logLevel . toLowerCase ( ) as keyof ClassThatLogs ;
572
574
573
- const isDevMode = this . getEnvVarsService ( ) . getDevMode ( ) ;
574
- const INDENTATION : LogJsonIndent = isDevMode ? LogJsonIndent . PRETTY : LogJsonIndent . COMPACT ;
575
-
576
- this . console [ consoleMethod ] ( JSON . stringify ( log . getAttributes ( ) , this . removeCircularDependencies ( ) , INDENTATION ) ) ;
575
+ this . console [ consoleMethod ] ( JSON . stringify ( log . getAttributes ( ) , this . removeCircularDependencies ( ) , this . logIndentation ) ) ;
577
576
}
578
577
579
578
/**
@@ -666,6 +665,19 @@ class Logger extends Utility implements ClassThatLogs {
666
665
this . logFormatter = logFormatter || new PowertoolLogFormatter ( ) ;
667
666
}
668
667
668
+ /**
669
+ * If the `POWERTOOLS_DEV' env variable is set,
670
+ * it adds JSON indentation for pretty printing logs.
671
+ *
672
+ * @private
673
+ * @returns {void }
674
+ */
675
+ private setLogIndentation ( ) : void {
676
+ if ( this . getEnvVarsService ( ) . getDevMode ( ) ) {
677
+ this . logIndentation = LogJsonIndent . PRETTY ;
678
+ }
679
+ }
680
+
669
681
/**
670
682
* It sets the Logger's instance log level.
671
683
*
@@ -735,6 +747,7 @@ class Logger extends Utility implements ClassThatLogs {
735
747
this . setLogFormatter ( logFormatter ) ;
736
748
this . setPowertoolLogData ( serviceName , environment ) ;
737
749
this . setLogEvent ( ) ;
750
+ this . setLogIndentation ( ) ;
738
751
739
752
this . addPersistentLogAttributes ( persistentLogAttributes ) ;
740
753
0 commit comments