Conversation
- 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
Test Coverage ReportOverall Coverage: 94.34%
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
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 |
- 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
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)
|
🎉 This PR is included in version 6.48.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
LOG_FORMATenvironment variable for flexible log output configuration%time,%level,%name,%msg%msg(minimal) for daemonized environments where journald already provides metadata[%time] %level (%name): %msgfor standalone usefirst8..tofirst4..last4format9fd82b35-6789-abcd→9fd8..abcdtruncateId()function in logger.tsTest plan
LOG_FORMAT=%msgLOG_FORMAT="[%time] %level (%name): %msg"Closes #213