Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 7 additions & 21 deletions packages/logger/src/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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 = <PowertoolsLogData>{
private readonly powertoolsLogData: PowertoolsLogData = <PowertoolsLogData>{
sampleRateValue: 0,
};
/**
Expand All @@ -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<string, 'temp' | 'persistent'> = new Map();
readonly #keys: Map<string, 'temp' | 'persistent'> = new Map();
/**
* This is the initial log leval as set during the initialization of the logger.
*
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -1199,8 +1187,6 @@ class Logger extends Utility implements LoggerInterface {
if (this.isValidLogLevel(logLevelValue)) {
this.logLevel = LogLevelThreshold[logLevelValue];
this.#initialLogLevel = this.logLevel;

return;
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/logger/src/formatter/LogFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/logger/src/formatter/PowertoolsLogFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 0 additions & 2 deletions packages/logger/tests/e2e/basicFeatures.middy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
});
Expand Down
Loading