Caddy v2, how to disable output?

In my Caddyfile v2, I have each site with the directive:

        log {
                output file caddy.log

When I run caddy, I’m still getting logging to the screen, as well as to the log file, caddy.log. How do I turn off logging on the screen (stdout/stderr)?

You’re probably starting Caddy with caddy run, which runs the server in the foreground of the terminal: Command Line — Caddy Documentation

Caddy v2 can be run in the background instead. Either use a service manager, like systemd or nssm, OR use the caddy start command instead: Command Line — Caddy Documentation

I think the OP is actually asking why access logs also appear in stdout instead of only in the designated caddy.log file.

The answer is because Caddy’s new structured logging works a little differently. There’s one log by default (called default – in case you forget, just remember that it’s the default!) which prints to stderr by default. And by default, all logs ingest all messages. Unless they are filtered. Simply adding a log – in this case, a caddy.log file – doesn’t exclude it from other loggers.

Our hope is that, as people evolve to using more modern logging techniques, they will configure the default log the way they need, then leave filtering and processing up to the log aggregator or whatever system is ingesting the logs, rather than having a more complex Caddy configuration do the work.

Anyway, you’re free to ignore any log messages you want, if you are not ignoring them at some other output. :slight_smile:

To answer what I think was the original question, though, it can be disabled by filtering for logs which do not exist; but this can’t be done from the Caddyfile, you’d have to drop down to the JSON (which isn’t that bad, really): JSON Config Structure - Caddy Documentation

Thanks again both of you!

I like the new logs a lot. I’m using caddy start so I can just keep them in a file.

Depending on how your shell works, you might be able to do caddy start 2> output.txt.

Yep! Thats what I’ve got going.

A little off-topic, I really like the JSON output. Are there any tools you know of to analyze the log file / JSON output? There are lots of tools to analyze the common log format, but itd be great to track this latency info here too.

1 Like

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