Skip to content

feat(logging): add LOG_FORMAT env var and improve session ID truncation#215

Merged
polaz merged 6 commits intomainfrom
feat/#213-featlogging-add-env-vars-to-exclude-redundant-fiel
Jan 25, 2026
Merged

feat(logging): add LOG_FORMAT env var and improve session ID truncation#215
polaz merged 6 commits intomainfrom
feat/#213-featlogging-add-env-vars-to-exclude-redundant-fiel

Conversation

@polaz
Copy link
Copy Markdown
Member

@polaz polaz commented Jan 25, 2026

Summary

  • Add LOG_FORMAT environment variable for flexible log output configuration
    • Supports nginx-style tokens: %time, %level, %name, %msg
    • Default: %msg (minimal) for daemonized environments where journald already provides metadata
    • Full format: [%time] %level (%name): %msg for standalone use
  • Change session ID truncation from first8.. to first4..last4 format
    • Example: 9fd82b35-6789-abcd9fd8..abcd
    • Better identifiability while keeping logs compact
  • Add centralized truncateId() function in logger.ts

Test plan

  • All 4183 unit tests pass
  • Lint passes
  • Build succeeds
  • Manual testing: verify minimal format works with LOG_FORMAT=%msg
  • Manual testing: verify full format works with LOG_FORMAT="[%time] %level (%name): %msg"

Closes #213

- Add LOG_FORMAT environment variable for flexible log output configuration
  - Supports nginx-style tokens: %time, %level, %name, %msg
  - Default: "%msg" (minimal) for daemonized environments where journald
    already provides timestamp, hostname, and process name
  - Full format: "[%time] %level (%name): %msg" for standalone use
- Change session ID truncation format from first8.. to first4..last4
  - Example: "9fd82b35-6789-abcd" → "9fd8..abcd"
  - Makes it easier to distinguish sessions while keeping logs compact
- Add centralized truncateId() function in logger.ts for consistent usage
- Update all inline substring calls to use the new function
- Document LOG_FORMAT presets in .env.example

Closes #213
Copilot AI review requested due to automatic review settings January 25, 2026 15:24
@github-actions
Copy link
Copy Markdown

github-actions bot commented Jan 25, 2026

Test Coverage Report

Overall Coverage: 94.34%

Metric Percentage
Statements 93.76%
Branches 85.4%
Functions 84.26%
Lines 94.34%

View detailed coverage report

@codecov
Copy link
Copy Markdown

codecov bot commented Jan 25, 2026

Codecov Report

❌ Patch coverage is 58.97436% with 16 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/logger.ts 22.22% 13 Missing and 1 partial ⚠️
src/oauth/session-store.ts 71.42% 2 Missing ⚠️

📢 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 adds flexible log format configuration via the LOG_FORMAT environment variable and improves session ID truncation from first8.. to first4..last4 format for better identifiability in logs.

Changes:

  • Add LOG_FORMAT environment variable with two preset formats: minimal (%msg) for daemonized environments and full ([%time] %level (%name): %msg) for standalone use
  • Change session ID truncation from first 8 characters to first 4 + ".." + last 4 characters across all logging functions
  • Add centralized truncateId() function in logger.ts and update OAuth files to import from it

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/logger.ts Adds truncateId function and LOG_FORMAT configuration with pino-pretty options
src/logging/access-log.ts Updates truncateSessionId to use first4..last4 format
src/utils/request-logger.ts Updates truncateId to use first4..last4 format
src/logging/types.ts Updates comment documenting session ID truncation format
src/oauth/storage/memory.ts Imports and uses truncateId from centralized logger
src/oauth/session-store.ts Imports and uses truncateId from centralized logger
src/oauth/endpoints/token.ts Imports and uses truncateId from centralized logger
src/oauth/endpoints/callback.ts Imports and uses truncateId from centralized logger
src/oauth/endpoints/authorize.ts Imports and uses truncateId from centralized logger
src/middleware/oauth-auth.ts Imports and uses truncateId from centralized logger
tests/unit/logger.test.ts Adds tests for LOG_FORMAT constant and truncateId function
tests/unit/utils/request-logger.test.ts Updates tests for new first4..last4 truncation format
tests/unit/logging/access-log.test.ts Updates tests for new first4..last4 truncation format
tests/unit/oauth/endpoints/token.test.ts Adds truncateId mock implementation
tests/unit/oauth/endpoints/callback.test.ts Adds truncateId mock implementation
tests/unit/oauth/endpoints/authorize.test.ts Adds truncateId mock implementation
tests/unit/middleware/oauth-auth.test.ts Adds truncateId mock implementation
.env.example Documents LOG_FORMAT configuration options

polaz added 3 commits January 25, 2026 17:42
- Add convertToPinoFormat() to transform %time, %level, %name, %msg to pino-pretty placeholders
- Add getIgnoredFields() to dynamically hide unused fields based on format tokens
- Add runtime type guard for truncateId() to resolve CodeQL type confusion warning
- Centralize truncateId imports in access-log.ts and request-logger.ts
- Add truncateId to logger mocks in test files
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 20 out of 20 changed files in this pull request and generated no new comments.

@polaz polaz enabled auto-merge (squash) January 25, 2026 16:11
@polaz polaz merged commit df655f2 into main Jan 25, 2026
15 of 16 checks passed
@polaz polaz deleted the feat/#213-featlogging-add-env-vars-to-exclude-redundant-fiel branch January 25, 2026 16:17
sw-release-bot bot pushed a commit that referenced this pull request Jan 25, 2026
## [6.48.0](v6.47.1...v6.48.0) (2026-01-25)

### Features

* **logging:** add LOG_FORMAT env var and improve session ID truncation ([#215](#215)) ([df655f2](df655f2)), closes [#213](#213)
* **mcp:** MCP Ecosystem Compatibility - Graceful Startup, Static Manifest, and Release Pipeline Improvements ([#212](#212)) ([2ecb70d](2ecb70d)), closes [#210](#210)
@sw-release-bot
Copy link
Copy Markdown

🎉 This PR is included in version 6.48.0 🎉

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.

feat(logging): Add env vars to exclude redundant fields in daemonized environments

3 participants