diff --git a/packages/logger/src/Logger.ts b/packages/logger/src/Logger.ts index 507d0879fa..6f79cedfaf 100644 --- a/packages/logger/src/Logger.ts +++ b/packages/logger/src/Logger.ts @@ -117,7 +117,7 @@ class Logger extends Utility implements LoggerInterface { /** * Custom config service instance used to configure the logger. */ - private customConfigService?: ConfigServiceInterface; + private readonly customConfigService?: ConfigServiceInterface; /** * Whether to print the Lambda invocation event in the logs. */ @@ -149,7 +149,7 @@ class Logger extends Utility implements LoggerInterface { /** * Standard attributes managed by Powertools that will be logged in all log items. */ - private powertoolsLogData: PowertoolsLogData = { + private readonly powertoolsLogData: PowertoolsLogData = { sampleRateValue: 0, }; /** @@ -169,14 +169,14 @@ class Logger extends Utility implements LoggerInterface { /** * Flag used to determine if the logger is initialized. */ - #isInitialized = false; + readonly #isInitialized: boolean = false; /** * Map used to hold the list of keys and their type. * * Because keys of different types can be overwritten, we keep a list of keys that were added and their last * type. We then use this map at log preparation time to pick the last one. */ - #keys: Map = new Map(); + readonly #keys: Map = new Map(); /** * This is the initial log leval as set during the initialization of the logger. * @@ -263,7 +263,9 @@ class Logger extends Utility implements LoggerInterface { public constructor(options: ConstructorOptions = {}) { super(); const { customConfigService, ...rest } = options; - this.setCustomConfigService(customConfigService); + this.customConfigService = customConfigService + ? customConfigService + : undefined; // all logs are buffered until the logger is initialized this.setOptions(rest); this.#isInitialized = true; @@ -1135,20 +1137,6 @@ class Logger extends Utility implements LoggerInterface { }; } - /** - * Set the Logger's customer config service instance, which will be used - * to fetch environment variables. - * - * @param customConfigService - The custom config service - */ - private setCustomConfigService( - customConfigService?: ConfigServiceInterface - ): void { - this.customConfigService = customConfigService - ? customConfigService - : undefined; - } - /** * Set the initial Logger log level based on the following order: * 1. If a log level is set using AWS Lambda Advanced Logging Controls, it sets it. @@ -1199,8 +1187,6 @@ class Logger extends Utility implements LoggerInterface { if (this.isValidLogLevel(logLevelValue)) { this.logLevel = LogLevelThreshold[logLevelValue]; this.#initialLogLevel = this.logLevel; - - return; } } diff --git a/packages/logger/src/formatter/LogFormatter.ts b/packages/logger/src/formatter/LogFormatter.ts index 9e6a57197a..89273f73d2 100644 --- a/packages/logger/src/formatter/LogFormatter.ts +++ b/packages/logger/src/formatter/LogFormatter.ts @@ -183,7 +183,7 @@ abstract class LogFormatter { * * @param timezone - IANA time zone identifier (e.g., "Asia/Dhaka"). */ - #getDateFormatter = (timezone: string): Intl.DateTimeFormat => { + readonly #getDateFormatter = (timezone: string): Intl.DateTimeFormat => { const twoDigitFormatOption = '2-digit'; const validTimeZone = Intl.supportedValuesOf('timeZone').includes(timezone) ? timezone diff --git a/packages/logger/src/formatter/PowertoolsLogFormatter.ts b/packages/logger/src/formatter/PowertoolsLogFormatter.ts index d68d3ff91c..e76657c0d6 100644 --- a/packages/logger/src/formatter/PowertoolsLogFormatter.ts +++ b/packages/logger/src/formatter/PowertoolsLogFormatter.ts @@ -24,7 +24,7 @@ class PowertoolsLogFormatter extends LogFormatter { * * This can be a set of keys or an array of keys. */ - #logRecordOrder?: LogRecordOrderKeys; + readonly #logRecordOrder?: LogRecordOrderKeys; public constructor(options?: PowertoolsLogFormatterOptions) { super(); diff --git a/packages/logger/tests/e2e/basicFeatures.middy.test.ts b/packages/logger/tests/e2e/basicFeatures.middy.test.ts index 81071435b8..56d0c28b19 100644 --- a/packages/logger/tests/e2e/basicFeatures.middy.test.ts +++ b/packages/logger/tests/e2e/basicFeatures.middy.test.ts @@ -269,12 +269,10 @@ describe('Logger E2E tests, basic functionalities middy usage', () => { const logMessages = invocationLogs[i].getFunctionLogs(); // Check that the X-Ray Trace ID is logged on every log - const traceIds: string[] = []; for (const message of logMessages) { const log = TestInvocationLogs.parseFunctionLog(message); expect(log).toHaveProperty('xray_trace_id'); expect(log.xray_trace_id).toMatch(XRAY_TRACE_ID_REGEX); - traceIds.push(log.xray_trace_id as string); } } });