File tree Expand file tree Collapse file tree 2 files changed +8
-10
lines changed Expand file tree Collapse file tree 2 files changed +8
-10
lines changed Original file line number Diff line number Diff line change @@ -257,7 +257,7 @@ class Logger extends Utility implements LoggerInterface {
257
257
}
258
258
259
259
/**
260
- * Alias for addTemporaryLogAttributes .
260
+ * It adds the given temporary attributes (key-value pairs) to all log items generated by this Logger instance .
261
261
*
262
262
* @param {LogAttributes } attributes
263
263
* @returns {void }
@@ -454,7 +454,7 @@ class Logger extends Utility implements LoggerInterface {
454
454
} catch ( error ) {
455
455
throw error ;
456
456
} finally {
457
- Logger . injectLambdaContextAfterOrOnError ( loggerRef , { } , options ) ;
457
+ if ( options ?. clearState ) loggerRef . resetState ( ) ;
458
458
}
459
459
460
460
return result ;
@@ -463,8 +463,9 @@ class Logger extends Utility implements LoggerInterface {
463
463
}
464
464
465
465
/**
466
- * @deprecated This method is deprecated and will be removed in the future major versions.
466
+ * @deprecated This method is deprecated and will be removed in the future major versions. Use { @link resetState()} instead.
467
467
*/
468
+ /* istanbul ignore next */
468
469
public static injectLambdaContextAfterOrOnError (
469
470
logger : Logger ,
470
471
_persistentAttributes : LogAttributes ,
Original file line number Diff line number Diff line change @@ -2395,16 +2395,13 @@ describe('Class: Logger', () => {
2395
2395
2396
2396
test ( 'it awaits the decorated method correctly' , async ( ) => {
2397
2397
// Prepare
2398
- const injectLambdaContextAfterOrOnErrorSpy = jest . spyOn (
2399
- Logger ,
2400
- 'injectLambdaContextAfterOrOnError'
2401
- ) ;
2402
2398
const logger = new Logger ( {
2403
2399
logLevel : 'DEBUG' ,
2404
2400
} ) ;
2401
+ const resetStateSpy = jest . spyOn ( logger , 'resetState' ) ;
2405
2402
const consoleSpy = jest . spyOn ( logger [ 'console' ] , 'info' ) ;
2406
2403
class LambdaFunction implements LambdaInterface {
2407
- @logger . injectLambdaContext ( )
2404
+ @logger . injectLambdaContext ( { clearState : true } )
2408
2405
public async handler (
2409
2406
_event : unknown ,
2410
2407
_context : unknown
@@ -2426,12 +2423,12 @@ describe('Class: Logger', () => {
2426
2423
await handler ( { } , context ) ;
2427
2424
2428
2425
// Assess
2429
- expect ( consoleSpy ) . toBeCalledTimes ( 1 ) ;
2426
+ expect ( consoleSpy ) . toHaveBeenCalledTimes ( 1 ) ;
2430
2427
// Here we assert that the logger.info method is called before the cleanup function that should always
2431
2428
// be called ONLY after the handler has returned. If logger.info is called after the cleanup function
2432
2429
// it means the decorator is NOT awaiting the handler which would cause the test to fail.
2433
2430
expect ( consoleSpy . mock . invocationCallOrder [ 0 ] ) . toBeLessThan (
2434
- injectLambdaContextAfterOrOnErrorSpy . mock . invocationCallOrder [ 0 ]
2431
+ resetStateSpy . mock . invocationCallOrder [ 0 ]
2435
2432
) ;
2436
2433
} ) ;
2437
2434
You can’t perform that action at this time.
0 commit comments