Conversation
Problem: Access logs appeared as multiline JSON in journald/systemd because pino-pretty outputs structured objects after the message. Solution: - Add LOG_JSON env variable (default: false) for two mutually exclusive modes: - Plain mode: Single-line human-readable format via pino-pretty - JSON mode: Raw NDJSON output for log aggregators (Loki, ELK, Datadog) - Remove timestamp from access log message (pino already adds it) - Conditionally include accessLog object only in JSON mode Closes #207
Test Coverage ReportOverall Coverage: 93.58%
|
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Pull request overview
This PR fixes multiline log output in production environments (journald/systemd) by introducing a LOG_JSON environment variable that provides two mutually exclusive logging modes: plain text (default) for human-readable single-line output, and JSON mode for log aggregators. The fix removes duplicate timestamps from access log messages and conditionally includes the structured accessLog object only in JSON mode.
Changes:
- Added
LOG_JSONenvironment variable to toggle between plain text and JSON logging modes - Modified access log output to conditionally include structured data only in JSON mode
- Removed timestamp prefix from access log messages (pino already adds it)
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/logger.ts |
Added LOG_JSON export and conditional pino-pretty transport configuration |
src/logging/request-tracker.ts |
Added conditional logic to include accessLog object only in JSON mode |
src/logging/access-log.ts |
Removed timestamp from formatAccessLog output to avoid duplication |
tests/unit/logging/access-log.test.ts |
Updated test expectations to match new format without timestamp prefix |
docs/guide/configuration.md |
Added logging configuration documentation for LOG_JSON and LOG_FORMAT variables |
- Apply same LOG_JSON conditional to connection-tracker.ts - Remove LOG_FORMAT from docs table (already documented elsewhere)
|
🎉 This PR is included in version 6.45.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Summary
LOG_JSONenv variable (default:false) for two mutually exclusive log modesLOG_JSON=true): Raw NDJSON output for log aggregators (Loki, ELK, Datadog)accessLogobject only in JSON mode to prevent multiline outputTest plan
yarn lintpassesyarn test- 4071 tests passyarn buildcompletes successfullyyarn dev:sse- verify single-line output in terminalLOG_JSON=true yarn dev:sse 2>&1 | jq .- verify valid JSON outputCloses #207