Skip to content

Commit c2a0e98

Browse files
committed
Warn when flushed messages will be lost due to ALC
1 parent 5249f27 commit c2a0e98

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

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

+8
Original file line numberDiff line numberDiff line change
@@ -1451,6 +1451,14 @@ class Logger extends Utility implements LoggerInterface {
14511451
)
14521452
);
14531453
}
1454+
const AlcLogLevel =
1455+
this.getEnvVarsService().getAwsLogLevel() as keyof typeof LogLevelThreshold;
1456+
1457+
if (LogLevelThreshold[AlcLogLevel] > this.#bufferConfig.bufferAtVerbosity) {
1458+
this.#warnOnce(
1459+
'Advanced Loggging Controls (ALC) Log Level is less verbose than Log Buffering Log Level. Some logs might be missing.'
1460+
);
1461+
}
14541462

14551463
this.#buffer?.delete(traceId);
14561464
}

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

+24-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ 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', () => {
95+
it('outputs a warning when the Advanced Logging Configuration Log Level is less verbose than the Log Buffering Log Level', () => {
9696
// Assemble
9797
process.env.AWS_LAMBDA_LOG_LEVEL = 'INFO';
9898
const logger = new Logger({
@@ -114,6 +114,29 @@ describe('Buffer logs', () => {
114114
);
115115
});
116116

117+
it('When the buffer is flushed it outputs a warning if the Advanced Logging Configuration Log Level is less verbose than the Log Buffering Log Level', () => {
118+
// Assemble
119+
process.env.AWS_LAMBDA_LOG_LEVEL = 'INFO';
120+
const logger = new Logger({
121+
logLevel: LogLevel.DEBUG,
122+
logBufferOptions: { enabled: true, bufferAtVerbosity: 'DEBUG' },
123+
});
124+
125+
// Act
126+
logger.debug('This is a debug');
127+
logger.flushBuffer();
128+
129+
// Assess
130+
expect(console.warn).toHaveLogged(
131+
expect.objectContaining({
132+
message: expect.stringContaining(
133+
'Advanced Loggging Controls (ALC) Log Level is less verbose than Log Buffering Log Level. Some logs might be missing.'
134+
),
135+
level: LogLevel.WARN,
136+
})
137+
);
138+
});
139+
117140
it('outputs a warning when there is an error buffering the log', () => {
118141
// Prepare
119142
const logger = new Logger({ logBufferOptions: { maxBytes: 100 } });

0 commit comments

Comments
 (0)