Systemd caddy.service and logging

I’m setting up Caddy with systemd. In the caddy.service file it starts Caddy with:

ExecStart=/usr/local/bin/caddy -log stdout -agree=true -conf=/etc/caddy/Caddyfile -root=/var/tmp

I would prefer to have Caddy log to a ‘standard’ location, like /var/log/caddy. So, I tried to set that in the Caddyfile to override the caddy.service file, with log /var/log/caddy. However, that didn’t seem to work.

The only way I can get it to work (so far) is by modifying the caddy.service file to use -log /var/log/caddy/access.log. However, I’d prefer to not have to modify the default caddy.service file as distributed with downloads.

Maybe I’m missing something here? Any suggestions and tips greatly appreciated.

Logging to stdout will get caught by journald. The CLI -log flag records runtime info/errors, which you’ll probably want to be available and handy in the systemd journal. The Caddyfile log and errors directives specify logging for requests.

If you definitely need your runtime logs to be saved elsewhere, you will need to modify the service file. Perhaps you could look into using some config management tool like Ansible to keep any changes you make declarative in nature.

Matt,

Thanks for that clarification. I had misunderstood the difference. So, I think it’s fine for me as I have it. I’m already using Ansible to deploy my machine.

1 Like

so the command to see the logs is …

journalctl -f -u caddy