3 Logging
vBlackOut edited this page 2026-08-26 07:48:04 +02:00
This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Logging

ProxyAuth's logging has two independent layers, and most confusion about it comes from conflating them:

Layer Configured by Answers
Access log logging in config.json, plus log: in routes.yml What goes in a per-request log line, and which requests get one
Transport log in config.json Where every log line ends up — stdout, Loki, the /adm/logs buffer, or nowhere

They stack: the access log produces lines, the transport decides where they're written. Turning the access log off still leaves warnings and errors flowing through the transport — which is almost always what "disable logging on this noisy endpoint" is actually meant to achieve.

⚠️ GET /adm/logs only returns anything if log.type is set to "http". Every other mode ("local"/default, "loki", "disabled") never writes into the in-memory buffer that endpoint reads from — it'll return 200 OK with an empty body, not an error, so this is easy to miss.


Part 1 — The access log

One log line per request, in a format you define. It's produced by a middleware wrapped around the entire application, which means it sees every request: proxied routes, static routes, /auth, /logout, /reset-password, every /adm/* endpoint, 404s that matched no route, 403s from the IP blocklist, 429s from the rate limiter, and errors converted by the framework before any handler ran.

Configuration

"logging": {
  "enabled": true,
  "format": "[vhost] [ip] [method] [path] [status] [length] [user-agent] [x-forwarded-for] [error_detail]",
  "vhosts": {
    "internal.example.com": { "enabled": false },
    "git.proxyauth.app": { "log_file": "git.proxyauth.app.log" }
  },
  "routes": {
    "/healthz": false,
    "/metrics": false
  },
  "resource_sample_interval_secs": 1,
  "log_file": "access.log",
  "flush_interval_ms": 500
}
Key Type Default Description
enabled boolean true Proxy-wide switch. Also accepted as log (alias).
format string see below The line format. Also accepted as format-log (alias).
vhosts object {} Per-Host overrides, keyed by hostname. Unlisted hosts inherit enabled. Each entry can also set its own log_file — see Per-vhost/route log files below.
routes object {} Per-route overrides keyed by the route's prefix. A route's own log: in routes.yml wins over this.
resource_sample_interval_secs integer 1 Sampling interval for [cpu-usage]/[memory-usage]. Ignored if the format doesn't use them.
log_file string "access.log" Global access-log filename, written into /var/log/proxyauth/. Requests whose vhost/route has its own log_file go there instead — see below.
flush_interval_ms integer 500 How often buffered log writes — both this access log and the global proxyauth.log (see "local" below) — are flushed to disk. Lower for near-real-time visibility while tailing a file during debugging; higher to reduce flush syscalls under heavy request volume. Below roughly 50ms you're mostly defeating the point of buffering at all.

Default format:

[vhost] [ip] [method] [path] [status] [length] [user-agent] [x-forwarded-for] [error_detail]

Per-vhost/route log files

Any vhost (via logging.vhosts.<host>.log_file) or route (via log_file: in routes.yml) can be given its own dedicated log file instead of the shared global one:

"logging": {
  "vhosts": {
    "git.proxyauth.app": { "log_file": "git.proxyauth.app.log" }
  }
}

Resolution order, most specific first: route log_file (routes.yml) → vhost log_file (config.json) → global log_file. Every file is written into /var/log/proxyauth/ automatically — only a plain filename is accepted (log_file: "sub/dir/x.log" or an absolute path is rejected at startup, to close off path traversal). Files are opened lazily on first write and shared across every vhost/route that resolves to the same filename.

Buffered the same way as the global access log — see flush_interval_ms above for how quickly a line actually reaches disk.

Placeholders

Placeholder Value
[vhost] Host, normalized — port stripped, lowercased
[ip] Client IP as ProxyAuth resolved it (see the note below)
[path] Request path
[method] HTTP method
[status] Status code actually returned
[length] Response body size on the wire
[user-agent] User-Agent
[x-forwarded-for] The raw header, as received
[host] Host unnormalized, port included
[protocol] HTTP/1.1, HTTP/2.0, …
[query] Query string, - if absent
[referer] Referer ([referrer] also accepted)
[request-time] Total latency through the middleware, in ms
[cpu-usage] ProxyAuth's own CPU usage, sampled
[memory-usage] ProxyAuth's own RSS, sampled
[username] Authenticated identity, - where the route requires no login
[token-id] Token identifier (the old [tid:…] field)
[route] Index of the matched route
[time] Local timestamp
[error_detail] Error detail string set by a handler on a 4xx/5xx response, - on a normal 2xx. Also accepted as [error-detail]/[error].

Placeholder names are case-insensitive, and [user_agent]/[x_forwarded_for]/[request_time] are accepted alongside the hyphenated spellings.

Anything that isn't a recognized placeholder is emitted verbatim — a typo'd [stauts] shows up literally in your logs. That's deliberate: a visible typo is far easier to notice than a column that silently vanished.

[ip] vs [x-forwarded-for]

Not the same field, and the difference matters when you're reading logs during an incident.

[ip] is the address ProxyAuth acted on — the same trusted-proxy-aware resolution the rate limiter and the per-route allow_ips/deny_ips lists use. It only honours X-Forwarded-For/X-Real-IP when the connecting peer is in trust_proxy_forward_for (or is loopback); otherwise it's the socket peer address. See Rate Limiting.

[x-forwarded-for] is the raw header, spoofable by anyone when the peer isn't trusted. Log both if you want to spot forgery attempts; make decisions on [ip].

[length]

The number of bytes actually put on the wire, so if compression applied, this is the compressed size — equivalent to nginx's $body_bytes_sent, not $upstream_response_length.

[cpu-usage] / [memory-usage]

These describe the ProxyAuth process itself, not the request. They're read from /proc/self/{stat,statm} by a background ticker and cached in an atomic; the request path only does a relaxed load. Reading /proc per request would put a syscall and a file parse on the critical path.

Consequences worth knowing:

  • The value can be up to resource_sample_interval_secs stale. It's a coarse health signal, not per-request accounting.
  • The sampler isn't started at all unless the format actually references one of the two.
  • Non-Linux platforms report 0.

Turning the access log off

Five levels, most specific first:

# Where Scope
1 routes.yml → log: on the route That route
2 routes.yml → log: on the vhosts: group Every route in the group that doesn't set its own
3 config.json → logging.routes["<prefix>"] That route, by prefix
4 config.json → logging.vhosts["<host>"].enabled Every request arriving on that Host
5 config.json → logging.enabled Everything

Two properties that follow from where each level is evaluated:

Levels 4 and 5 are checked before the handler runs, so a silenced vhost doesn't even pay for capturing headers. Levels 1–3 are checked afterwards, since the matched route isn't known until routing has happened.

Level 4 also covers requests that match no route at all. That's the point: a 404 flood against one domain can be silenced without touching the others. Levels 1–3 can't do this — there's no route to carry the flag.

Route-level example:

routes:
  - prefix: /healthz
    target: http://127.0.0.1:3000
    required_login: false
    log: false

Group-level:

vhosts:
  - vhost: ["internal.example.com"]
    log: false
    routes:
      - prefix: /
        target: http://127.0.0.1:9000

log inherits exactly like need_csrf: route beats group, group beats global.

What stays visible when it's off

Only the per-request access line disappears. Diagnostic events keep flowing:

  • upstream errors, timeouts, body-read failures
  • IP-blocklist and allow_ips/deny_ips rejections
  • path-traversal attempts on static routes
  • token validation failures
  • rate-limit rejections

If you want true silence, that's log.type: "disabled" in Part 2 — but read the warning there first.


Performance

The format string is parsed once at startup into a token list; nothing is parsed per request. Per request the middleware does one Instant::now(), a handful of header lookups, and one string build. No lock is taken — the tracing subscriber owns its own writer synchronization.

With logging.enabled: false the middleware is a boolean load and a pass-through: no captures, no timer, no allocation.


Part 2 — Transport (log.type)

Where log lines — access and diagnostic alike — actually go. Exactly one mode is active at a time; there's no way to write to both stdout and the /adm/logs buffer.

log.type Destination Feeds /adm/logs?
"local" (default, or anything unrecognized, or omitted) stdout, local timestamps No
"loki" Grafana Loki, and stdout No
"http" In-memory ring buffer, exposed via /adm/logs Yes
"disabled" Nowhere No

"local" (default)

"log": { "type": "local" }

Writes directly to /var/log/proxyauth/proxyauth.log — the global application log: database/reset/revoke module diagnostics, startup messages, warnings, everything except request/access log lines (those go to access.log or a per-vhost/route override instead, never duplicated here). This is also the silent fallback for a typo in type — there's no validation error. If your logs aren't where you expect, check the spelling first.

Local (not UTC) timestamps. Buffered and flushed on the same logging.flush_interval_ms interval as the access log (default 500ms) — see Per-vhost/route log files above for the reasoning.

Good for: a self-contained deployment where you'd rather ProxyAuth own its own log file directly than depend on whatever launched it (an init script's stdout redirect, a container runtime's log driver, etc.) to land it somewhere useful.

"loki"

"log": {
  "type": "loki",
  "host": "http://loki.internal:3100"
}

Ships to a Loki push endpoint via tracing-loki, labeled app=proxyauth, with the process PID as an extra field. Still logs to stdout in parallel.

host is required in this mode — startup panics with "Missing Loki host config" if it's absent. Must be a valid URL.

Only proxyauth-originated events are forwarded to Loki; framework events from actix_web/actix_server are filtered out of the Loki stream (they still appear on stdout at warn level).

Good for: centralized search across a multi-instance deployment.

"http" — feeds /adm/logs

"log": {
  "type": "http",
  "write_max_logs": "2000"
}

Lines go into an in-memory ring buffer instead of stdout, which GET /adm/logs returns as plain text.

  • write_max_logs (default "1000") is the buffer capacity. Once full, the oldest line is evicted.
  • Must be below 100,000 — the process refuses to start otherwise.
  • Entirely in memory. Nothing on disk, cleared on every restart.
  • No stdout output at all for ProxyAuth's own logs in this mode. If you also want a persistent copy, use "loki", or ship stdout from "local".

Sizing note: with the access log enabled, this buffer now receives a line for every request, not just the subset that used to be logged. At high traffic a 1000-line buffer may only hold a few seconds of history. Either raise write_max_logs, or silence high-volume routes via logging.routes — /adm/logs is a troubleshooting aid, not a log store.

Good for: quick visibility into one running instance without external infrastructure.

"disabled"

"log": { "type": "disabled" }

No output anywhere — the tracing registry is initialized with no writer layer at all. This kills everything, including the diagnostic warnings that logging.enabled: false deliberately preserves: upstream failures, blocked IPs, path-traversal attempts, token validation errors.

If your goal is "less noise" rather than "no observability", use logging.enabled: false (or the per-vhost/per-route switches) instead. Reach for "disabled" only when something else already captures everything relevant, or under a hard no-logging requirement.


Log levels

Regardless of mode, default filtering is:

  • proxyauth=trace — ProxyAuth's own code logs everything from trace up.
  • actix_web=warn, actix_server=warn — the framework is much quieter.

Override with the standard RUST_LOG environment variable, which takes priority:

RUST_LOG=proxyauth=debug,actix_web=info proxyauth

In "loki" mode the level shipped to Loki is capped at INFO even if your local filter is more verbose — finer events still reach stdout, just not Loki.


Choosing a mode

If you... Use
Run under systemd/Docker and already collect stdout "local"
Run a cluster and want centralized search "loki"
Want to check recent logs without external tooling "http"
Have a strict no-logging requirement "disabled"

Recipes

Combined-log-like format, with latency:

"format": "[time] [ip] [method] [path] [protocol] [status] [length] [request-time] [referer] [user-agent]"

Multi-tenant, tracking who did what:

"format": "[time] [vhost] [ip] [username] [method] [path] [status] [length] [request-time]"

Debugging a proxy chain:

"format": "[time] [ip] [x-forwarded-for] [host] [method] [path] [query] [status]"

[ip] shows what ProxyAuth decided; [x-forwarded-for] shows what was claimed. A mismatch means either trust_proxy_forward_for doesn't list your load balancer, or someone is forging the header.

Everything except two hot endpoints:

"logging": {
  "enabled": true,
  "format": "[time] [vhost] [ip] [method] [path] [status] [length]",
  "routes": { "/healthz": false, "/metrics": false }
}

A busy vhost with its own log file, checked frequently:

"logging": {
  "vhosts": {
    "git.proxyauth.app": { "log_file": "git.proxyauth.app.log" }
  },
  "flush_interval_ms": 200
}
tail -f /var/log/proxyauth/git.proxyauth.app.log

A shorter flush_interval_ms here is worth it specifically while actively tailing a file during an incident — the trade-off is more frequent flush syscalls, which matters more under sustained heavy load than while watching one vhost.


See also