Skip to content

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

@polaz

Description

@polaz

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

Implementation Notes

  • Modify src/utils/logger.ts to parse LOG_FORMAT tokens
  • Default to %msg (minimal) when LOG_FORMAT not set
  • Update session ID truncation helper to use first4..last4 format
  • Should work alongside LOG_JSON=true (JSON mode ignores LOG_FORMAT or uses it for field selection)
  • Document both presets in .env.example

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions