Expected Behavior
When flushOnErrorLog is enabled in the log buffer options, calling logger.critical() should flush the buffer before emitting the log — the same behavior as logger.error(). CRITICAL is more severe than ERROR, so it should at minimum have the same flush-on-error semantics.
Current Behavior
error() checks flushOnErrorLog and flushes the buffer (Logger.ts:411-413), but critical() (Logger.ts:387-392) does not. This means buffered diagnostic logs (debug, info, etc.) are flushed when an ERROR is logged but silently lost when a CRITICAL is logged.
Code snippet
import { Logger } from '@aws-lambda-powertools/logger';
const logger = new Logger({
logLevel: 'ERROR',
logBufferOptions: { enabled: true, flushOnErrorLog: true },
});
logger.debug('diagnostic info that should be preserved');
logger.critical('system failure');
// Expected: the debug log is flushed to output before the critical log
// Actual: the debug log is silently discarded
Steps to Reproduce
- Create a Logger with
logBufferOptions: { enabled: true, flushOnErrorLog: true }
- Log a debug message:
logger.debug('diagnostic info')
- Log a critical message:
logger.critical('system failure')
- Observe that the buffered debug log was never output
Possible Solution
The most direct fix is to add the same flush check to critical(). However, a more robust approach would be to centralise the flush-on-error logic inside processLogItem(), which all log level methods already funnel through. processLogItem could check whether the incoming log level meets a severity threshold (e.g. >= LogLevelThreshold.ERROR) and flush before processing. This would make the individual methods simple one-liners and prevent the issue from recurring if new severity levels are added in the future.
Powertools for AWS Lambda (TypeScript) version
2.33.0
AWS Lambda function runtime
22.x
Packaging format used
npm
Disclaimer: After creating an issue, please wait until it is triaged and confirmed by a maintainer before implementing it. This will reduce amount of rework and the chance that a pull request gets rejected.
Expected Behavior
When
flushOnErrorLogis enabled in the log buffer options, callinglogger.critical()should flush the buffer before emitting the log — the same behavior aslogger.error(). CRITICAL is more severe than ERROR, so it should at minimum have the same flush-on-error semantics.Current Behavior
error()checksflushOnErrorLogand flushes the buffer (Logger.ts:411-413), butcritical()(Logger.ts:387-392) does not. This means buffered diagnostic logs (debug, info, etc.) are flushed when an ERROR is logged but silently lost when a CRITICAL is logged.Code snippet
Steps to Reproduce
logBufferOptions: { enabled: true, flushOnErrorLog: true }logger.debug('diagnostic info')logger.critical('system failure')Possible Solution
The most direct fix is to add the same flush check to
critical(). However, a more robust approach would be to centralise the flush-on-error logic insideprocessLogItem(), which all log level methods already funnel through.processLogItemcould check whether the incoming log level meets a severity threshold (e.g.>= LogLevelThreshold.ERROR) and flush before processing. This would make the individual methods simple one-liners and prevent the issue from recurring if new severity levels are added in the future.Powertools for AWS Lambda (TypeScript) version
2.33.0
AWS Lambda function runtime
22.x
Packaging format used
npm
Disclaimer: After creating an issue, please wait until it is triaged and confirmed by a maintainer before implementing it. This will reduce amount of rework and the chance that a pull request gets rejected.