Skip to content

fix(logging): Access logs output single-line format with LOG_JSON mode#208

Merged
polaz merged 2 commits intomainfrom
feat/#207-fixlogging-access-logs-output-multiline-json-inste
Jan 25, 2026
Merged

fix(logging): Access logs output single-line format with LOG_JSON mode#208
polaz merged 2 commits intomainfrom
feat/#207-fixlogging-access-logs-output-multiline-json-inste

Conversation

@polaz
Copy link
Copy Markdown
Member

@polaz polaz commented Jan 25, 2026

Summary

  • Add LOG_JSON env variable (default: false) for two mutually exclusive log modes
  • Plain mode (default): Single-line human-readable format via pino-pretty for journald/systemd/console
  • JSON mode (LOG_JSON=true): Raw NDJSON output for log aggregators (Loki, ELK, Datadog)
  • Remove duplicate timestamp from access log message (pino already adds it in prefix/JSON)
  • Conditionally include accessLog object only in JSON mode to prevent multiline output

Test plan

  • yarn lint passes
  • yarn test - 4071 tests pass
  • yarn build completes successfully
  • Manual verification:
    • Plain mode: yarn dev:sse - verify single-line output in terminal
    • JSON mode: LOG_JSON=true yarn dev:sse 2>&1 | jq . - verify valid JSON output

Closes #207

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
Copilot AI review requested due to automatic review settings January 25, 2026 04:23
@github-actions
Copy link
Copy Markdown

github-actions bot commented Jan 25, 2026

Test Coverage Report

Overall Coverage: 93.58%

Metric Percentage
Statements 93.05%
Branches 84.76%
Functions 82.92%
Lines 93.58%

View detailed coverage report

@codecov
Copy link
Copy Markdown

codecov bot commented Jan 25, 2026

Codecov Report

❌ Patch coverage is 50.00000% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/logging/connection-tracker.ts 50.00% 1 Missing and 1 partial ⚠️
src/logging/request-tracker.ts 50.00% 1 Missing and 1 partial ⚠️
src/logger.ts 50.00% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_JSON environment 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)
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

@polaz polaz merged commit 499854d into main Jan 25, 2026
26 of 27 checks passed
@polaz polaz deleted the feat/#207-fixlogging-access-logs-output-multiline-json-inste branch January 25, 2026 04:42
sw-release-bot bot pushed a commit that referenced this pull request Jan 25, 2026
## [6.45.1](v6.45.0...v6.45.1) (2026-01-25)

### Bug Fixes

* **logging:** Access logs output single-line format with LOG_JSON mode ([#208](#208)) ([499854d](499854d)), closes [#207](#207)
@sw-release-bot
Copy link
Copy Markdown

🎉 This PR is included in version 6.45.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(logging): Access logs output multiline JSON instead of single condensed line

2 participants