@@ -221,7 +221,7 @@ class Logger extends Utility implements LoggerInterface {
221
221
* @param attributes - The attributes to add to all log items.
222
222
*/
223
223
public appendKeys ( attributes : LogAttributes ) : void {
224
- this . #appendAnyKeys ( attributes , 'temp' ) ;
224
+ this . #appendKeys ( attributes , 'temp' ) ;
225
225
}
226
226
227
227
/**
@@ -230,7 +230,7 @@ class Logger extends Utility implements LoggerInterface {
230
230
* @param attributes - The attributes to add to all log items.
231
231
*/
232
232
public appendPersistentKeys ( attributes : LogAttributes ) : void {
233
- this . #appendAnyKeys ( attributes , 'persistent' ) ;
233
+ this . #appendKeys ( attributes , 'persistent' ) ;
234
234
}
235
235
236
236
/**
@@ -287,13 +287,6 @@ class Logger extends Utility implements LoggerInterface {
287
287
* @param extraInput - The extra input to log.
288
288
*/
289
289
public debug ( input : LogItemMessage , ...extraInput : LogItemExtraInput ) : void {
290
- for ( const extra of extraInput ) {
291
- if ( ! ( extra instanceof Error ) && ! ( typeof extra === 'string' ) ) {
292
- for ( const key of Object . keys ( extra ) ) {
293
- this . #checkReservedKeyAndWarn( key ) ;
294
- }
295
- }
296
- }
297
290
this . processLogItem ( LogLevelThreshold . DEBUG , input , extraInput ) ;
298
291
}
299
292
@@ -673,10 +666,10 @@ class Logger extends Utility implements LoggerInterface {
673
666
* @param attributes - The attributes to add to the log item.
674
667
* @param type - The type of the attributes to add.
675
668
*/
676
- #appendAnyKeys ( attributes : LogAttributes , type : 'temp' | 'persistent' ) : void {
669
+ #appendKeys ( attributes : LogAttributes , type : 'temp' | 'persistent' ) : void {
677
670
for ( const attributeKey of Object . keys ( attributes ) ) {
678
671
if ( this . #checkReservedKeyAndWarn( attributeKey ) === false ) {
679
- this . #keys. set ( attributeKey , 'temp' ) ;
672
+ this . #keys. set ( attributeKey , type ) ;
680
673
}
681
674
}
682
675
if ( type === 'temp' ) {
@@ -732,6 +725,11 @@ class Logger extends Utility implements LoggerInterface {
732
725
} else {
733
726
const { message : inputMessage , ...rest } = input ;
734
727
message = inputMessage ;
728
+ for ( const key of Object . keys ( rest ) ) {
729
+ if ( this . #checkReservedKeyAndWarn( key ) ) {
730
+ delete rest [ key ] ;
731
+ }
732
+ }
735
733
otherInput = rest ;
736
734
}
737
735
@@ -758,6 +756,13 @@ class Logger extends Utility implements LoggerInterface {
758
756
merge ( additionalAttributes , otherInput ) ;
759
757
// then we merge the extra input attributes (if any)
760
758
for ( const item of extraInput ) {
759
+ if ( ! ( item instanceof Error ) && ! ( typeof item === 'string' ) ) {
760
+ for ( const key of Object . keys ( item ) ) {
761
+ if ( this . #checkReservedKeyAndWarn( key ) ) {
762
+ delete item [ key ] ;
763
+ }
764
+ }
765
+ }
761
766
const attributes : LogAttributes =
762
767
item instanceof Error
763
768
? { error : item }
@@ -1123,7 +1128,7 @@ class Logger extends Utility implements LoggerInterface {
1123
1128
private setPowertoolsLogData (
1124
1129
serviceName ?: ConstructorOptions [ 'serviceName' ] ,
1125
1130
environment ?: ConstructorOptions [ 'environment' ] ,
1126
- persistentKeys : ConstructorOptions [ 'persistentKeys' ] = { }
1131
+ persistentKeys ? : ConstructorOptions [ 'persistentKeys' ]
1127
1132
) : void {
1128
1133
this . addToPowertoolsLogData ( {
1129
1134
awsRegion : this . getEnvVarsService ( ) . getAwsRegion ( ) ,
@@ -1137,7 +1142,7 @@ class Logger extends Utility implements LoggerInterface {
1137
1142
this . getEnvVarsService ( ) . getServiceName ( ) ||
1138
1143
this . getDefaultServiceName ( ) ,
1139
1144
} ) ;
1140
- this . appendPersistentKeys ( persistentKeys ) ;
1145
+ persistentKeys && this . appendPersistentKeys ( persistentKeys ) ;
1141
1146
}
1142
1147
}
1143
1148
0 commit comments