Skip to content

fix(logger): flush log buffer on critical() when flushOnErrorLog is e… - #5227

Merged
svozza merged 2 commits into
aws-powertools:mainfrom
vishwakt:fix/critical-flush-on-error-log
May 7, 2026
Merged

svozza merged 2 commits into
aws-powertools:mainfrom
vishwakt:fix/critical-flush-on-error-log

Conversation

@vishwakt

@vishwakt vishwakt commented May 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Changes

Centralizes the flush-on-error logic from error() into processLogItem() so that any log level >= ERROR (including CRITICAL) will automatically flush the buffer when flushOnErrorLog is enabled.

Previously, only error() checked flushOnErrorLog and flushed the buffer. critical(), despite being more severe, did not flush — causing buffered diagnostic logs to be silently discarded.

What changed

  • Logger.ts: Removed the buffer flush check from error() and moved it into processLogItem(), which all log level methods funnel through. The condition checks logLevel >= LogLevelThreshold.ERROR && logLevel < LogLevelThreshold.SILENT to cover both ERROR and CRITICAL while excluding SILENT.
  • logBuffer.test.ts: Added two unit tests:
    • Verifies critical() flushes the buffer when flushOnErrorLog is enabled (default)
    • Verifies critical() does not flush the buffer when flushOnErrorLog is explicitly disabled

Issue number: Closes #5210


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

…nabled

Centralizes the flush-on-error logic from error() into processLogItem()
so that any log level >= ERROR (including CRITICAL) will automatically
flush the buffer when flushOnErrorLog is enabled.

Previously, only error() checked flushOnErrorLog and flushed the buffer.
critical(), despite being more severe, did not flush — causing buffered
diagnostic logs to be silently discarded.

Closes aws-powertools#5210
@boring-cyborg

boring-cyborg Bot commented May 7, 2026

Copy link
Copy Markdown

Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need.
In the meantime, check out the #typescript channel on our Powertools for AWS Lambda Discord: Invite link

@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added the size/M PR between 30-99 LOC label May 7, 2026
@svozza

svozza commented May 7, 2026

Copy link
Copy Markdown
Contributor

One minor comment but other than that LGTM!

@svozza
svozza self-requested a review May 7, 2026 11:33
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added size/M PR between 30-99 LOC and removed size/M PR between 30-99 LOC labels May 7, 2026
@svozza
svozza merged commit 853b44f into aws-powertools:main May 7, 2026
36 checks passed
@boring-cyborg

boring-cyborg Bot commented May 7, 2026

Copy link
Copy Markdown

Awesome work, congrats on your first merged pull request and thank you for helping improve everyone's experience!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M PR between 30-99 LOC

2 participants