@@ -140,9 +140,7 @@ class Logger extends Utility implements LoggerInterface {
140
140
*/
141
141
#buffer: [ number , Parameters < Logger [ 'createAndPopulateLogItem' ] > ] [ ] = [ ] ;
142
142
143
-
144
- #context: Record < string , Array < Parameters < Logger [ 'createAndPopulateLogItem' ] > > > = { }
145
-
143
+ #context: Record < string , Array < [ number , string ] > > = { } ;
146
144
147
145
/**
148
146
* Flag used to determine if the logger is initialized.
@@ -841,9 +839,7 @@ class Logger extends Utility implements LoggerInterface {
841
839
* @param logLevel - The log level
842
840
* @param log - The log item to print
843
841
*/
844
- private printLog ( logLevel : number , log : LogItem ) : void {
845
- log . prepareForPrint ( ) ;
846
-
842
+ private printLog ( logLevel : number , log : LogItem | string ) : void {
847
843
const consoleMethod =
848
844
logLevel === LogLevelThreshold . CRITICAL
849
845
? 'error'
@@ -853,11 +849,17 @@ class Logger extends Utility implements LoggerInterface {
853
849
> ) ;
854
850
855
851
this . console [ consoleMethod ] (
856
- JSON . stringify (
857
- log . getAttributes ( ) ,
858
- this . getJsonReplacer ( ) ,
859
- this . logIndentation
860
- )
852
+ typeof log === 'string' ? log : this . formatLog ( log )
853
+ ) ;
854
+ }
855
+
856
+ private formatLog ( log : LogItem ) : string {
857
+ log . prepareForPrint ( ) ;
858
+
859
+ return JSON . stringify (
860
+ log . getAttributes ( ) ,
861
+ this . getJsonReplacer ( ) ,
862
+ this . logIndentation
861
863
) ;
862
864
}
863
865
@@ -874,17 +876,14 @@ class Logger extends Utility implements LoggerInterface {
874
876
extraInput : LogItemExtraInput
875
877
) : void {
876
878
if ( logLevel >= this . logLevel ) {
877
- const xRayTraceId = this . envVarsService . getXrayTraceId ( ) ;
878
-
879
+ const xRayTraceId = this . envVarsService . getXrayTraceId ( ) as string ;
880
+
879
881
// Print all log items in the context
880
882
if ( this . #context[ xRayTraceId ] ) {
881
883
for ( const contextItem of this . #context[ xRayTraceId ] ) {
882
- this . printLog (
883
- logLevel ,
884
- this . createAndPopulateLogItem ( ...contextItem )
885
- ) ;
884
+ this . printLog ( ...contextItem ) ;
886
885
}
887
-
886
+
888
887
// Clear the context after flushing
889
888
// This also removes entries from other X-Ray trace IDs
890
889
this . #context = { } ;
@@ -903,9 +902,14 @@ class Logger extends Utility implements LoggerInterface {
903
902
904
903
// Add the log item to the context
905
904
const context = this . #context[ xRayTraceId ] ?? [ ] ;
906
- context . push ( [ logLevel , input , extraInput ] ) ;
905
+ context . push ( [
906
+ logLevel ,
907
+ this . formatLog (
908
+ this . createAndPopulateLogItem ( logLevel , input , extraInput )
909
+ ) ,
910
+ ] ) ;
907
911
908
- // Assign the updated context to the context property
912
+ // Assign the updated context to the context property
909
913
// This also removes other X-Ray trace IDs from the context
910
914
this . #context = {
911
915
[ xRayTraceId ] : context ,
0 commit comments