Skip to content

feat(logging): add LOG_FILTER for access log noise reduction #290

@polaz

Description

@polaz

Problem

Claude Code clients poll GET / every second for MCP server availability checks. This creates significant log noise:

192.168.95.254 5c1e..f025 - - GET / 200 1ms | - - | - - | -

Solution

Add LOG_FILTER environment variable to filter out specific request patterns from access logs.

Format

JSON array of filter rules. A request is skipped if ALL conditions in a rule match:

LOG_FILTER='[{"method":"GET","path":"/","userAgent":"claude-code"}]'

Filter rule properties

Property Type Description
method string HTTP method (exact match, case-insensitive)
path string Request path (exact match, or prefix match if ends with *)
userAgent string Substring match in User-Agent header (case-insensitive)

All properties are optional. If a property is omitted, it matches any value.

Examples

Skip Claude Code polling (default):

LOG_FILTER='[{"method":"GET","path":"/","userAgent":"claude-code"}]'

Multiple filters - skip various polling sources:

LOG_FILTER='[
  {"method":"GET","path":"/","userAgent":"claude-code"},
  {"method":"GET","path":"/health"},
  {"method":"GET","path":"/","userAgent":"prometheus"},
  {"method":"HEAD","path":"/*"}
]'

Skip all GET requests to root (any User-Agent):

LOG_FILTER='[{"method":"GET","path":"/"}]'

Skip requests from specific monitoring tool:

LOG_FILTER='[{"userAgent":"datadog"}]'

Log all requests (disable filtering):

LOG_FILTER='[]'

Default behavior

  • Default: Filters Claude Code polling requests ([{"method":"GET","path":"/","userAgent":"claude-code"}])
  • Set LOG_FILTER='[]' to log all requests
  • If set to invalid JSON: log warning at startup, log all requests

Implementation checklist

  • Add LOG_FILTER parsing in src/config.ts with Zod schema validation
  • Add filter check in access log middleware (src/server.ts) before opening request stack
  • If request matches any filter rule, skip access logging but process request normally
  • Log info at startup showing number of active filter rules
  • Add unit tests for filter matching logic
  • Update documentation:
    • Add to docs/CONFIGURATION.md under Logging section
    • Include all examples from this issue
    • Document that filtered requests are still processed, just not logged

Time estimate

1.5h (including documentation)

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