Skip to content

Commit ca76e12

Browse files
committed
chore: update usage of deprecated method
1 parent 12c60c5 commit ca76e12

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

packages/logger/src/Logger.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ class Logger extends Utility implements LoggerInterface {
257257
}
258258

259259
/**
260-
* Alias for addTemporaryLogAttributes.
260+
* It adds the given temporary attributes (key-value pairs) to all log items generated by this Logger instance.
261261
*
262262
* @param {LogAttributes} attributes
263263
* @returns {void}
@@ -454,7 +454,7 @@ class Logger extends Utility implements LoggerInterface {
454454
} catch (error) {
455455
throw error;
456456
} finally {
457-
Logger.injectLambdaContextAfterOrOnError(loggerRef, {}, options);
457+
if (options?.clearState) loggerRef.resetState();
458458
}
459459

460460
return result;
@@ -463,8 +463,9 @@ class Logger extends Utility implements LoggerInterface {
463463
}
464464

465465
/**
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.
467467
*/
468+
/* istanbul ignore next */
468469
public static injectLambdaContextAfterOrOnError(
469470
logger: Logger,
470471
_persistentAttributes: LogAttributes,

packages/logger/tests/unit/Logger.test.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2395,16 +2395,13 @@ describe('Class: Logger', () => {
23952395

23962396
test('it awaits the decorated method correctly', async () => {
23972397
// Prepare
2398-
const injectLambdaContextAfterOrOnErrorSpy = jest.spyOn(
2399-
Logger,
2400-
'injectLambdaContextAfterOrOnError'
2401-
);
24022398
const logger = new Logger({
24032399
logLevel: 'DEBUG',
24042400
});
2401+
const resetStateSpy = jest.spyOn(logger, 'resetState');
24052402
const consoleSpy = jest.spyOn(logger['console'], 'info');
24062403
class LambdaFunction implements LambdaInterface {
2407-
@logger.injectLambdaContext()
2404+
@logger.injectLambdaContext({ clearState: true })
24082405
public async handler(
24092406
_event: unknown,
24102407
_context: unknown
@@ -2426,12 +2423,12 @@ describe('Class: Logger', () => {
24262423
await handler({}, context);
24272424

24282425
// Assess
2429-
expect(consoleSpy).toBeCalledTimes(1);
2426+
expect(consoleSpy).toHaveBeenCalledTimes(1);
24302427
// Here we assert that the logger.info method is called before the cleanup function that should always
24312428
// be called ONLY after the handler has returned. If logger.info is called after the cleanup function
24322429
// it means the decorator is NOT awaiting the handler which would cause the test to fail.
24332430
expect(consoleSpy.mock.invocationCallOrder[0]).toBeLessThan(
2434-
injectLambdaContextAfterOrOnErrorSpy.mock.invocationCallOrder[0]
2431+
resetStateSpy.mock.invocationCallOrder[0]
24352432
);
24362433
});
24372434

0 commit comments

Comments
 (0)