Exclude logs from default logger

1. The problem I’m having:

I am running Caddy as a Docker container and wanted to set up a Docker health check for the container.
In another help thread I found the suggestion to call http://127.0.0.1:2019/reverse_proxy/upstreams to see if Caddy is running.

The problem I’m having is that every request to /reverse_proxy/upstreams is logged in the caddy logs, which makes it difficult to read the rest of the log entries.

I have seen that there is a global option to exclude certain loggers from the standard log:

log [name] {
    output  <writer_module> ...
    format  <encoder_module> ...
    level   <level>
    include <namespaces...>
    exclude <namespaces...>
}

I tried this by setting:

log {
    exclude admin.api
}

I was expecting the requests to /reverse_proxy/upstreams to no longer be logged, but they are still being logged.

Have I missed something?
How is this supposed to work?

2. Error messages and/or full log output:

{"level":"info","ts":1747228059.4953809,"msg":"maxprocs: Leaving GOMAXPROCS=20: CPU quota undefined"}
{"level":"info","ts":1747228059.4955418,"msg":"GOMEMLIMIT is updated","package":"github.com/KimMachineGun/automemlimit/memlimit","GOMEMLIMIT":30137031475,"previous":9223372036854775807}
{"level":"info","ts":1747228059.501346,"msg":"using config from file","file":"/etc/caddy/Caddyfile"}
{"level":"info","ts":1747228059.5019329,"msg":"adapted config to JSON","adapter":"caddyfile"}
{"level":"info","ts":1747228059.573569,"logger":"admin","msg":"admin endpoint started","address":"localhost:2019","enforce_origin":false,"origins":["//localhost:2019","//[::1]:2019","//127.0.0.1:2019"]}
{"level":"warn","ts":1747228059.5737877,"logger":"http.auto_https","msg":"server is listening only on the HTTP port, so no automatic HTTPS will be applied to this server","server_name":"srv0","http_port":80}
{"level":"info","ts":1747228059.5740166,"logger":"tls.cache.maintenance","msg":"started background certificate maintenance","cache":"0xc000524b00"}
{"level":"warn","ts":1747228059.5740778,"logger":"http","msg":"HTTP/2 skipped because it requires TLS","network":"tcp","addr":":80"}
{"level":"warn","ts":1747228059.5740871,"logger":"http","msg":"HTTP/3 skipped because it requires TLS","network":"tcp","addr":":80"}
{"level":"info","ts":1747228059.57409,"logger":"http.log","msg":"server running","name":"srv0","protocols":["h1","h2","h3"]}
{"level":"info","ts":1747228059.5747132,"msg":"autosaved config (load with --resume flag)","file":"/config/caddy/autosave.json"}
{"level":"info","ts":1747228059.5747628,"msg":"serving initial configuration"}
{"level":"info","ts":1747228059.6234548,"logger":"tls","msg":"storage cleaning happened too recently; skipping for now","storage":"FileStorage:/data/caddy","instance":"123c05b6-11f8-4094-b9bd-7c842cd0bec3","try_again":1747314459.6234481,"try_again_in":86399.99999892}
{"level":"info","ts":1747228059.6340053,"logger":"tls","msg":"finished cleaning storage units"}
{"level":"info","ts":1747228060.5221102,"logger":"admin.api","msg":"received request","method":"GET","host":"127.0.0.1:2019","uri":"/reverse_proxy/upstreams","remote_ip":"127.0.0.1","remote_port":"49028","headers":{"Accept":["*/*"],"Connection":["close"],"User-Agent":["Wget"]}}
{"level":"info","ts":1747228061.5728157,"logger":"admin.api","msg":"received request","method":"GET","host":"127.0.0.1:2019","uri":"/reverse_proxy/upstreams","remote_ip":"127.0.0.1","remote_port":"49034","headers":{"Accept":["*/*"],"Connection":["close"],"User-Agent":["Wget"]}}
{"level":"info","ts":1747228062.620836,"logger":"admin.api","msg":"received request","method":"GET","host":"127.0.0.1:2019","uri":"/reverse_proxy/upstreams","remote_ip":"127.0.0.1","remote_port":"49050","headers":{"Accept":["*/*"],"Connection":["close"],"User-Agent":["Wget"]}}
...

3. Caddy version:

v2.10.0 h1:fonubSaQKF1YANl8TXqGcn4IbIRUDdfAkpcsfI/vX5U=

4. How I installed and ran Caddy:

a. System environment:

Docker image caddy:2.10.0

b. Command:

docker compose up

c. Service/unit/compose file:

services:
  reverse-proxy:
    container_name: caddy
    image: caddy:2.10.0
    ports:
      - "80:80"
    healthcheck:
      test: wget --no-verbose --tries=1 http://127.0.0.1:2019/reverse_proxy/upstreams || exit 1
      interval: 1s
      timeout: 3s
      retries: 5
    volumes:
      - ./caddy/Caddyfile:/etc/caddy/Caddyfile:ro
      - ./caddy-data:/data

d. My complete Caddy config:

{
	log {
		exclude admin.api
	}
}

localhost:80 {
	respond "Hello"
}

Ran into it myself and fixed here. It should go in the next release.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.