How to change caddy itself's log output format while I using caddyfile with systemd

1. Caddy version (caddy version):

v2.3.0 h1:fnrqJLa3G5vfxcxmOH/+kJOcunPLhSBnjgIvjXV/QTA=

2. How I run Caddy:

a. System environment:

Debian 10, Linux 4.19.0-14-amd64 #1 SMP Debian 4.19.171-2 (2021-01-30) x86_64 GNU/Linux

b. Command:

Just an officially systemd service file

If command on terminal will be OK, it outputs console format as I wish.

c. Service/unit/compose file:

# /lib/systemd/system/caddy.service
# caddy.service
# For using Caddy with a config file.
# Make sure the ExecStart and ExecReload commands are correct
# for your installation.
# See for instructions.
# WARNING: This service does not use the --resume flag, so if you
# use the API to make changes, they will be overwritten by the
# Caddyfile next time the service is restarted. If you intend to
# use Caddy's API to configure it, add the --resume flag to the
# `caddy run` command or use the caddy-api.service file instead.


ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile
ExecReload=/usr/bin/caddy reload --config /etc/caddy/Caddyfile
; Environment=XDG_DATA_HOME=/var
; Environment=XDG_CONFIG_HOME=/var


d. My complete Caddyfile or JSON config:

None about config file, I think. Just question for how to change caddy itself’s output log format

3. The problem I’m having:

Cannot set caddy itself’s log format.

4. Error messages and/or full log output:

Current journalctl caddy.service log look like this, JSON format, human unfriendly:

Apr 19 02:44:23 srv caddy[32659]: {"level":"info","ts":1618771463.3738742,"msg":"using provided configuration","config_file":"/etc/caddy/Caddyfile","config_adapter":""}
Apr 19 02:44:23 srv caddy[32659]: {"level":"info","ts":1618771463.384001,"logger":"admin","msg":"admin endpoint started","address":"tcp/localhost:2019","enforce_origin":false,"origins":["","localhost:2019","[::1]:2019"]}
Apr 19 02:44:23 srv caddy[32659]: {"level":"info","ts":1618771463.3851924,"logger":"http","msg":"enabling automatic HTTP->HTTPS redirects","server_name":"srv0"}
Apr 19 02:44:23 srv caddy[32659]: {"level":"info","ts":1618771463.3854547,"logger":"http","msg":"enabling automatic HTTP->HTTPS redirects","server_name":"srv1"}
Apr 19 02:44:23 srv caddy[32659]: {"level":"info","ts":1618771463.3865013,"logger":"tls.cache.maintenance","msg":"started background certificate maintenance","cache":"0xc000306000"}

5. What I already tried:

I have been read all reletave documents but looks only JSON file define log format, but I use caddyfile.

6. Links to relevant resources:

It’s not currently possible in Caddy v2.3.0, but it will be possible in v2.4.0 (available since beta 2) via global options. It was added in this PR:

But you should be aware that Caddy emits structured logs, which don’t really have a way to be “human readable”, really. You generally should be using other tooling to format the logs how you like, for example jq which is a CLI tool for manipulating JSON inputs.

Thanks, my “human readable” means just not like JSON add extra no-use information, just like general console log is enough, I only check it when I change my configuration. Anyway, thanks for your help!

Well, JSON is pretty human readable. Just look for "msg":

But like I said, with v2.4.0-beta.2, you can configure global options to use the console writer which you might prefer.

The docs for that were added in this PR, but won’t be live until v2.4.0 stable is out (but it already is pretty stable, we just haven’t merged in all the features and improvements we wanted to add yet)

Sounds good, the official site’s current version is 2.4.0-beta1 and looks add DNS challenge plugin only available from site or compile by myself, but I don’t know how to compile, maybe I need to wait some days.

It’s very easy to build Caddy. You just need to install Go (just follow the official instructions on the Go site, it’s simple), then install xcaddy (just a static binary, like Caddy), then run a single command to build Caddy with plugins.

I will try, thanks for your help!

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