Skip to content

fix: end bun cluster log lines with a newline when log_date_format is set - #6165

Open
redpancho wants to merge 1 commit into
Unitech:developmentfrom
redpancho:fix/bun-cluster-log-date-format-newline
Open

redpancho wants to merge 1 commit into
Unitech:developmentfrom
redpancho:fix/bun-cluster-log-date-format-newline

Conversation

@redpancho

Copy link
Copy Markdown
Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes (test/e2e/cli/bun.sh on Bun 1.4.2, Linux)
Fixed tickets none filed
License MIT
Doc PR n/a

Problem

When PM2 runs on Bun, cluster mode apps use lib/ProcessContainerBun.js, which overrides console.log/info/warn/error. When the message has no trailing newline, only the branch with no log_date_format adds one. With log_date_format set, each entry is written as `${date}: ${msg}` with no newline, so the out and error log files put every entry on one line:

2026-09-27T00:00:03: first message2026-09-27T00:47:07: second message2026-09-27T00:49:05: third message

pm2 logs still looks correct while streaming, because it prints each bus packet on its own line. Only the log files on disk (and the pm2 logs history shown at startup, which is read from those files) are affected. Fork mode and Node cluster mode are unaffected. Reproduced on 7.0.4 and on current development.

Fix

Normalize the trailing newline once and use it for both the dated and the plain output. JSON output (log_type: json) and the process.stdout.write/process.stderr.write overrides are unchanged, since those writers already pass through whatever newline the caller includes.

Test

Added a case to test/e2e/cli/bun.sh. It starts a fixture in cluster mode (-i 1) with --log-date-format "YYYY", logs two lines to stdout and two to stderr, then checks that each entry is on its own YYYY: message line in both log files. Without the fix, the out-log check fails. With the fix, the whole of bun.sh passes.

🤖 Generated with Claude Code

… set

The console.log/info/warn/error overrides in ProcessContainerBun.js only
appended a trailing newline in the plain branch. With log_date_format set,
every entry was written without one, so cluster mode log files under Bun
ran all entries together on a single line.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@CLAassistant

CLAassistant commented Sep 27, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants