Skip to content

Commit 2e2df56

Browse files
committed
fix(logger): Output a warning when the ALC log level is less verbose than log buffer
1 parent 48e93fd commit 2e2df56

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

Diff for: packages/logger/src/Logger.ts

+8
Original file line numberDiff line numberDiff line change
@@ -1378,6 +1378,14 @@ class Logger extends Utility implements LoggerInterface {
13781378
this.#bufferConfig.bufferAtVerbosity =
13791379
LogLevelThreshold[bufferAtLogLevel];
13801380
}
1381+
const AlcLogLevel =
1382+
this.getEnvVarsService().getAwsLogLevel() as keyof typeof LogLevelThreshold;
1383+
1384+
if (LogLevelThreshold[AlcLogLevel] > this.#bufferConfig.bufferAtVerbosity) {
1385+
this.#warnOnce(
1386+
'Advanced Loggging Controls (ALC) Log Level is higher than Log Buffering Log Level. Buffered logs will be filtered by ALC'
1387+
);
1388+
}
13811389
}
13821390

13831391
/**

Diff for: packages/logger/tests/unit/logBuffer.test.ts

+22
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,28 @@ describe('Buffer logs', () => {
9292
);
9393
});
9494

95+
it('outputs a warning when the Advanced Logging Configuration Log Level is higher than the Log Buffering Log Level', () => {
96+
// Assemble
97+
process.env.AWS_LAMBDA_LOG_LEVEL = 'INFO';
98+
const logger = new Logger({
99+
logLevel: LogLevel.DEBUG,
100+
logBufferOptions: { enabled: true, bufferAtVerbosity: 'DEBUG' },
101+
});
102+
103+
// Act
104+
logger.debug('This is a debug');
105+
106+
// Assess
107+
expect(console.warn).toHaveLogged(
108+
expect.objectContaining({
109+
message: expect.stringContaining(
110+
'Advanced Loggging Controls (ALC) Log Level is higher than Log Buffering Log Level. Buffered logs will be filtered by ALC'
111+
),
112+
level: LogLevel.WARN,
113+
})
114+
);
115+
});
116+
95117
it('outputs a warning when there is an error buffering the log', () => {
96118
// Prepare
97119
const logger = new Logger({ logBufferOptions: { maxBytes: 100 } });

0 commit comments

Comments
 (0)