Share log file for all hosts?

I start caddy via systemctl on Ubuntu so I believe I need to include a log directive in my Caddyfile, as output is otherwise lost (sent to stderr of a background/disconnected process).

But while the default log format includes the host name, it appears that I must set up logging for every single host that I configure, i.e. I cannot set this in the global options, the best I can do is include a snippet, so I end up with a Caddyfile like this:

(logging) {
    log {
        output file /var/log/access.log
        format json {
            time_format iso8601
        }
    }
}
example.com {
    import logging
    ⋮
}
www.example.com {
    import logging
    ⋮
}
api.example.com {
    import logging
    ⋮
}
⋮

Am I missing something? How do others deal with log files?

The log directive only enables access logs for Caddy. Error and other runtime logs are printed to stdout. If you’re running Caddy as a service, you should be able to find them in your system logs using journalctl -u caddy.

Using a snippet for logging is the correct approach if you want access logs for all sites.

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