forked from zereight/gitlab-mcp
-
Notifications
You must be signed in to change notification settings - Fork 1
feat(logging): Add env vars to exclude redundant fields in daemonized environments #213
Copy link
Copy link
Closed
Labels
Description
Problem
When running in daemonized environments like systemd with journald, log output contains redundant information:
Jan 25 16:27:13 gitlab-mcp.sw.foundation node[39785]: [16:27:13.276] INFO (gitlab-mcp): StreamableHTTP endpoint endpoint=http://0.0.0.0:3333/mcp note=modern, supports SSE + JSON-RPC
The journald already provides:
- Timestamp (
Jan 25 16:27:13) - Hostname (
gitlab-mcp.sw.foundation) - Process name and PID (
node[39785])
Our logger then duplicates:
- Timestamp (
[16:27:13.276]) - Log level (
INFO) - Daemon name (
(gitlab-mcp))
Additionally, session IDs in logs are truncated awkwardly:
session=9fd82b35..
Proposed Solution
1. LOG_FORMAT Environment Variable
Add LOG_FORMAT environment variable (similar to nginx log_format) for flexible log output configuration.
Format Tokens
| Token | Description | Example |
|---|---|---|
%time |
Timestamp | [16:27:13.276] |
%level |
Log level | INFO |
%name |
Logger name | gitlab-mcp |
%msg |
Log message with structured data | StreamableHTTP endpoint endpoint=http://... |
Presets
minimal (default) - for daemonized environments:
LOG_FORMAT="%msg"Output:
StreamableHTTP endpoint endpoint=http://0.0.0.0:3333/mcp note=modern, supports SSE + JSON-RPC
full - standalone/development:
LOG_FORMAT="[%time] %level (%name): %msg"Output:
[16:27:13.276] INFO (gitlab-mcp): StreamableHTTP endpoint endpoint=http://0.0.0.0:3333/mcp note=modern, supports SSE + JSON-RPC
Example .env Configuration
# Log format (nginx-style tokens: %time, %level, %name, %msg)
# Default: minimal format for daemonized environments
LOG_FORMAT="%msg"
# Full format for standalone/development (uncomment to enable):
# LOG_FORMAT="[%time] %level (%name): %msg"2. Improved Session ID Format
Change session ID truncation from prefix-only to prefix+suffix for better identification:
| Current | Proposed |
|---|---|
9fd82b35.. |
9fd8..2b35 |
Format: first 4 chars + .. + last 4 chars
This makes it easier to distinguish sessions while keeping logs compact.
Context
- Related to fix(logging): Apply LOG_JSON pattern to all logger calls (multiline output remains in 144 places) #209 (LOG_JSON pattern application)
- Deployment uses systemd on
192.168.95.53with journald for log aggregation - Journald already captures all metadata, making app-level fields redundant
Implementation Notes
- Modify
src/utils/logger.tsto parse LOG_FORMAT tokens - Default to
%msg(minimal) when LOG_FORMAT not set - Update session ID truncation helper to use
first4..last4format - Should work alongside
LOG_JSON=true(JSON mode ignores LOG_FORMAT or uses it for field selection) - Document both presets in
.env.example
Reactions are currently unavailable