@@ -284,7 +284,12 @@ class Logger extends Utility implements ClassThatLogs {
284
284
285
285
descriptor . value = ( event , context , callback ) => {
286
286
287
- const initialPersistentAttributes = Logger . injectLambdaContextBefore ( this , event , context , options ) ;
287
+ let initialPersistentAttributes = { } ;
288
+ if ( options && options . clearState === true ) {
289
+ initialPersistentAttributes = { ...this . getPersistentLogAttributes ( ) } ;
290
+ }
291
+
292
+ Logger . injectLambdaContextBefore ( this , event , context , options ) ;
288
293
289
294
/* eslint-disable @typescript-eslint/no-non-null-assertion */
290
295
let result : unknown ;
@@ -301,24 +306,20 @@ class Logger extends Utility implements ClassThatLogs {
301
306
} ;
302
307
}
303
308
304
- public static injectLambdaContextAfterOrOnError ( logger : Logger , initialPersistentAttributes : LogAttributes = { } , options ?: HandlerOptions ) : void {
309
+ public static injectLambdaContextAfterOrOnError ( logger : Logger , initialPersistentAttributes : LogAttributes , options ?: HandlerOptions ) : void {
305
310
if ( options && options . clearState === true ) {
306
311
logger . setPersistentLogAttributes ( initialPersistentAttributes ) ;
307
312
}
308
313
}
309
314
310
- public static injectLambdaContextBefore ( logger : Logger , event : unknown , context : Context , options ?: HandlerOptions ) : LogAttributes | undefined {
315
+ public static injectLambdaContextBefore ( logger : Logger , event : unknown , context : Context , options ?: HandlerOptions ) : void {
311
316
logger . addContext ( context ) ;
312
317
313
318
let shouldLogEvent = undefined ;
314
319
if ( options && options . hasOwnProperty ( 'logEvent' ) ) {
315
320
shouldLogEvent = options . logEvent ;
316
321
}
317
322
logger . logEventIfEnabled ( event , shouldLogEvent ) ;
318
-
319
- if ( options && options . clearState === true ) {
320
- return { ...logger . getPersistentLogAttributes ( ) } ;
321
- }
322
323
}
323
324
324
325
/**
0 commit comments