Caddy2 disable access_log

1. My Caddy version (caddy -version):

v2.0.0-beta9

2. How I run Caddy:

systemd service file, updated to work with caddy 2. Caddyfile adapted to caddy2.

ExecStart=/usr/local/bin/caddy2 run --adapter caddyfile --config /etc/caddy2/Caddyfile

a. System environment:

Centos 7.7 on Digital Ocean

b. Command:

paste command here

c. Service/unit/compose file:

paste full file contents here

d. My complete Caddyfile:

myapp.example {
  tls me@myapp.example {
    load /etc/ssl/caddy2
  }

  reverse_proxy / :8000 {
    header_up Host {host}
    header_up X-Real-IP {remote}
    header_up X-Forwarded-For {remote}
    header_up X-Forwarded-Port {server_port}
    header_up X-Forwarded-Proto {scheme}
  }
}

3. The problem I’m having:

I’m proxying to a fairly high-traffic service (100s req/sec), and the systemd-journal process is using ~30% CPU (caddy2 uses ~10%, and the service itself around 8%). I have no need for the access logs, so I’d like to disable them completely.

The v2 docs mention logging in a few places, but its not clear if its possible to disable the access log from within a Caddyfile. It documents logging, but its not really clear how to disable the log, and there’s no examples of modifying the logs in the wikis.

My best guess is to use the admin UI to update the config:

{
  logging: {
    logs: {
      access: {
        writer: {
          output: "discard"
        }
      }
    }
  }
}

However, when I try to PATCH the config, I get this error:

$ curl -X PUT -H "Content-Type: application/json" -d '{"logging":{"logs":{"access":{"writer":{"output":"discard"}}}}}' localhost:2019/config/logging
{"error":"loading new config: json: unknown field \"logging\""}

Are there any complete examples of configuring the logger in caddy2?

TIA,
Paul

Hi Paul, and thanks for trying Caddy 2 while it’s still in beta!

First, I’d recommend upgrading to beta 10, since it fixes a bug related to only enabling the access logs if explicitly configured: http: Only enable access logs if configured · caddyserver/caddy@af26a03 · GitHub

That should probably solve your problem. (Logging is not yet configurable via the Caddyfile, that’s coming.)

Incidentally, your API request is close but not quite right. The path /config/logging traverses into the logging field:

{
    "apps": {...},
    "logging": {/* gets you into here */}
}

Thus, specifying {"logging": ...} as a field in your payload doesn’t make sense, because you already traversed into it. If your payload is just {"logs":{"access":{"writer":{"output":"discard"}}}} I suspect it will work?

Thanks @matt, upgrading to beta10 seems to have solved it. I was also tinkering with several config json formats trying to disable it, here’s what I’ve ended up that seems to work in beta10, if anyone else needs it:

{
  "logging": {
    "logs": {
      "access": {
        "writer": {
          "output": "discard"
        }
      }
    }
  },
  "apps": {
    "http": {
      ...

To be clear, you shouldn’t need to put all logs to the discard if you just want to disable the HTTP access logs. They aren’t enabled by default, so you don’t need to alter your logging config like that:

{
  "apps": {
    "http": {
      ...

Maybe I’m missing something. Wouldn’t putting it at “logging/logs/default” disable all logging? I assumed that having it at “logging/logs/access” would just disable the access logs.

Another possibility I tried was “logging/logs/http.log.access”, based on this part of the docs:

Access logs document HTTP requests as they come in; they use the namespace http.log.access

but that was in beta9, so I’m not sure which actually fixed it.

Your goal is to disable HTTP access logs, right?

The answer is, don’t enable them. Enabling them is done in the definition of your HTTP servers: Home · caddyserver/caddy Wiki · GitHub (see the “logs” field).

All you have to do is not enable them, you don’t have to mess with the global logger configs at all.

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