1
+ import { Console } from 'node:console' ;
2
+ import { randomInt } from 'node:crypto' ;
1
3
import { Utility } from '@aws-lambda-powertools/commons' ;
2
4
import type { HandlerMethodDecorator } from '@aws-lambda-powertools/commons/types' ;
3
5
import type { Context , Handler } from 'aws-lambda' ;
4
6
import merge from 'lodash.merge' ;
5
- import { Console } from 'node:console' ;
6
- import { randomInt } from 'node:crypto' ;
7
7
import { EnvironmentVariablesService } from './config/EnvironmentVariablesService.js' ;
8
8
import { LogJsonIndent } from './constants.js' ;
9
- import { LogItem } from './formatter/LogItem.js' ;
9
+ import type { LogItem } from './formatter/LogItem.js' ;
10
10
import { PowertoolsLogFormatter } from './formatter/PowertoolsLogFormatter.js' ;
11
11
import type { ConfigServiceInterface } from './types/ConfigServiceInterface.js' ;
12
12
import type {
13
13
Environment ,
14
14
LogAttributes ,
15
+ LogFormatterInterface ,
15
16
LogLevel ,
16
17
LogLevelThresholds ,
17
- LogFormatterInterface ,
18
18
} from './types/Log.js' ;
19
19
import type {
20
- LogFunction ,
21
20
ConstructorOptions ,
21
+ CustomJsonReplacerFn ,
22
22
InjectLambdaContextOptions ,
23
+ LogFunction ,
23
24
LogItemExtraInput ,
24
25
LogItemMessage ,
25
26
LoggerInterface ,
26
27
PowertoolsLogData ,
27
- CustomJsonReplacerFn ,
28
28
} from './types/Logger.js' ;
29
29
30
30
/**
@@ -442,10 +442,7 @@ class Logger extends Utility implements LoggerInterface {
442
442
options ?: InjectLambdaContextOptions
443
443
) : HandlerMethodDecorator {
444
444
return ( _target , _propertyKey , descriptor ) => {
445
- /**
446
- * The descriptor.value is the method this decorator decorates, it cannot be undefined.
447
- */
448
- /* eslint-disable @typescript-eslint/no-non-null-assertion */
445
+ // biome-ignore lint/style/noNonNullAssertion: The descriptor.value is the method this decorator decorates, it cannot be undefined.
449
446
const originalMethod = descriptor . value ! ;
450
447
451
448
// eslint-disable-next-line @typescript-eslint/no-this-alias
@@ -463,8 +460,6 @@ class Logger extends Utility implements LoggerInterface {
463
460
let result : unknown ;
464
461
try {
465
462
result = await originalMethod . apply ( this , [ event , context , callback ] ) ;
466
- } catch ( error ) {
467
- throw error ;
468
463
} finally {
469
464
if ( options ?. clearState || options ?. resetKeys ) loggerRef . resetKeys ( ) ;
470
465
}
@@ -697,22 +692,24 @@ class Logger extends Utility implements LoggerInterface {
697
692
const references = new WeakSet ( ) ;
698
693
699
694
return ( key , value ) => {
700
- if ( this . #jsonReplacerFn) value = this . #jsonReplacerFn?.( key , value ) ;
695
+ let replacedValue = value ;
696
+ if ( this . #jsonReplacerFn)
697
+ replacedValue = this . #jsonReplacerFn?.( key , replacedValue ) ;
701
698
702
- if ( value instanceof Error ) {
703
- value = this . getLogFormatter ( ) . formatError ( value ) ;
699
+ if ( replacedValue instanceof Error ) {
700
+ replacedValue = this . getLogFormatter ( ) . formatError ( replacedValue ) ;
704
701
}
705
- if ( typeof value === 'bigint' ) {
706
- return value . toString ( ) ;
702
+ if ( typeof replacedValue === 'bigint' ) {
703
+ return replacedValue . toString ( ) ;
707
704
}
708
- if ( typeof value === 'object' && value !== null ) {
709
- if ( references . has ( value ) ) {
705
+ if ( typeof replacedValue === 'object' && replacedValue !== null ) {
706
+ if ( references . has ( replacedValue ) ) {
710
707
return ;
711
708
}
712
- references . add ( value ) ;
709
+ references . add ( replacedValue ) ;
713
710
}
714
711
715
- return value ;
712
+ return replacedValue ;
716
713
} ;
717
714
}
718
715
@@ -855,10 +852,10 @@ class Logger extends Utility implements LoggerInterface {
855
852
* @returns - The name of the log level
856
853
*/
857
854
private getLogLevelNameFromNumber ( logLevel : number ) : Uppercase < LogLevel > {
858
- let found ;
855
+ let found : Uppercase < LogLevel > | undefined ;
859
856
for ( const [ key , value ] of Object . entries ( this . logLevelThresholds ) ) {
860
857
if ( value === logLevel ) {
861
- found = key ;
858
+ found = key as Uppercase < LogLevel > ;
862
859
break ;
863
860
}
864
861
}
0 commit comments