The log file is empty

1. Caddy version (caddy version):

2.4.6

2. How I run Caddy:

As a service :

[Unit]
Description=Caddy
Documentation=https://caddyserver.com/docs/
After=network.target
[Service]
User=caddy
Group=caddy
ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile
ExecReload=/usr/bin/caddy reload --config /etc/caddy/Caddyfile
#TimeoutStopSec=5s
LimitNOFILE=1048576
LimitNPROC=512
PrivateTmp=true
PrivateDevices=true
ProtectHome=true
ProtectSystem=full
Environment=CADDYPATH=/etc/ssl/caddy
AmbientCapabilities=CAP_NET_BIND_SERVICE
AmbientCapabilities=CAP_NET_BIND_SERVICE
NoNewPrivileges=true
[Install]
WantedBy=multi-user.target
--

a. System environment:

ubuntu 20.04 lts

b. Command:

systemctl start caddy

c. Service/unit/compose file:

[Unit]
Description=Caddy
Documentation=https://caddyserver.com/docs/
After=network.target
[Service]
User=caddy
Group=caddy
ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile
ExecReload=/usr/bin/caddy reload --config /etc/caddy/Caddyfile
#TimeoutStopSec=5s
LimitNOFILE=1048576
LimitNPROC=512
PrivateTmp=true
PrivateDevices=true
ProtectHome=true
ProtectSystem=full
Environment=CADDYPATH=/etc/ssl/caddy
AmbientCapabilities=CAP_NET_BIND_SERVICE
AmbientCapabilities=CAP_NET_BIND_SERVICE
NoNewPrivileges=true
[Install]
WantedBy=multi-user.target
--

d. My complete Caddyfile or JSON config:

# Unless the file starts with a global options block, the first
# uncommented line is always the address of your site.
#
# To use your own domain name (with automatic HTTPS), first make
# sure your domain's A/AAAA DNS records are properly pointed to
# this machine's public IP, then replace ":80" below with your
# domain name}
flix.test.fr:8019 {
	reverse_proxy * 127.0.0.1:8096
	log {
		output file /var/log/caddy/access.log
	}
}

3. The problem I’m having:

Everything is fine but the /var/log/caddy/access.log file is empty (it has 777 r/w)

4. Error messages and/or full log output:

5. What I already tried:

I removed the log directive in the Caddyfile, same thing, as expected I suppose, empty access.log file.

I used the command

caddy fmt 

and

caddy fmt --overwrite

no change. The status of the service

systemctl status caddy

caddy.service - Caddy
     Loaded: loaded (/etc/systemd/system/caddy.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2022-01-15 13:30:03 CET; 2s ago
       Docs: https://caddyserver.com/docs/
   Main PID: 734735 (caddy)
      Tasks: 12 (limit: 38256)
     Memory: 8.2M
     CGroup: /system.slice/caddy.service
             └─734735 /usr/bin/caddy run --environ --config /etc/caddy/Caddyfile

janv. 15 13:30:03 fractal caddy[734735]: {"level":"info","ts":1642249803.4098778,"msg":"using provided configuration","config_file":"/etc/caddy/Caddyfile","config_adapter":""}
janv. 15 13:30:03 fractal caddy[734735]: {"level":"warn","ts":1642249803.4107473,"msg":"input is not formatted with 'caddy fmt'","adapter":"caddyfile","file":"/etc/caddy/Caddyfile","line":11}
janv. 15 13:30:03 fractal caddy[734735]: {"level":"info","ts":1642249803.414547,"logger":"admin","msg":"admin endpoint started","address":"tcp/localhost:2019","enforce_origin":false,"origins":["localhost:2019","[::1]:2019","127.0.0.1:2019"]}
janv. 15 13:30:03 fractal caddy[734735]: {"level":"info","ts":1642249803.4146883,"logger":"http","msg":"enabling automatic HTTP->HTTPS redirects","server_name":"srv0"}
janv. 15 13:30:03 fractal caddy[734735]: {"level":"info","ts":1642249803.4147425,"logger":"tls.cache.maintenance","msg":"started background certificate maintenance","cache":"0xc00023a070"}

6. Links to relevant resources:

The ProtectSystem=full directive in the systemd unit file sets the entire filesystem as read-only except for selected directories, /var/log is not one of them. You need to add ReadWritePaths=/var/log/caddy to the systemd unit file.

1 Like

Hi
thanks for the message. I added ReadWritePaths=/var/log/caddy to caddy.service file. Caddy seems to work, but the log file is still empty.
N

Did you reload the systemd daemon? You need to run:

sudo systemctl daemon-reload

You might need to reload the caddy service too

1 Like

Hi, yes I reloaded daemon, restarted caddy, connected to the machine in https (it is working fine). When I do systemctl status caddy
I get

caddy.service - Caddy
Loaded: loaded (/etc/systemd/system/caddy.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2022-01-15 15:15:22 CET; 33min ago
Docs: Welcome — Caddy Documentation
Process: 745226 ExecReload=/usr/bin/caddy reload --config /etc/caddy/Caddyfile (code=exited, status=0/SUCCESS)
Main PID: 742678 (caddy)
Tasks: 17 (limit: 38256)
Memory: 17.4M
CGroup: /system.slice/caddy.service
└─742678 /usr/bin/caddy run --environ --config /etc/caddy/Caddyfile

janv. 15 15:48:39 fractal caddy[742678]: {“level”:“error”,“ts”:1642258119.9736655,“logger”:“http.log.access”,“msg”:“handled request”,“request”:{“remote_addr”:“86.238.234.90:53613”,“proto”:“HTTP/2.0”,“method”:“GET”,“host”:“flix.test.fr:1337”,“uri”:"/web/auto52620fda9c302289>
janv. 15 15:48:39 fractal caddy[742678]: {“level”:“error”,“ts”:1642258119.9736996,“logger”:“http.log.access”,“msg”:“handled request”,“request”:{“remote_addr”:“86.238.234.90:53613”,“proto”:“HTTP/2.0”,“method”:“GET”,“host”:“flix.test.fr:1337”,“uri”:"/web/auto52bddd55c8b2c349>
janv. 15 15:48:39 fractal caddy[742678]: {“level”:“error”,“ts”:1642258119.9737227,“logger”:“http.log.access”,“msg”:“handled request”,“request”:{“remote_addr”:“86.238.234.90:53613”,“proto”:“HTTP/2.0”,“method”:“GET”,“host”:“flix.test.fr:1337”,“uri”:"/web/auto4f7f134543922aa7>
janv. 15 15:48:39 fractal caddy[742678]: {“level”:“error”,“ts”:1642258119.973735,“logger”:“http.log.access”,“msg”:“handled request”,“request”:{“remote_addr”:“86.238.234.90:53613”,“proto”:“HTTP/2.0”,“method”:“GET”,“host”:“flix.test.fr:1337”,“uri”:"/web/auto5204.62ff8c1d2a75>
janv. 15 15:48:40 fractal caddy[742678]: {“level”:“info”,“ts”:1642258120.0721877,“logger”:“http.log.access”,“msg”:“handled request”,“request”:{“remote_addr”:“86.238.234.90:53613”,“proto”:“HTTP/2.0”,“method”:“GET”,“host”:“flix.test.fr:1337”,“uri”:"/web/autoassets/splash/ipa>
janv. 15 15:48:40 fracta…

But the access.log is still empty !
N

Looks like your access logs are being written to stdout. Are you sure you’re running with the config you think you are? Did you configure /etc/caddy/Caddyfile?

Seems like you’re not using our official systemd service file. If you install Caddy with our apt repo, it comes with it.

Also see these docs for the right command to run to see your service logs without each line being truncated (notice the > at the end of each line indicating it being truncated)

Hi
Thanks for the email. I am not sure of anything, that’s why I am asking here.
I installed caddy through your repo and edited Caddyfile by adding the log directive.
I don’t know why I get the warning about the format of the Caddyfile and I tried
caddy fmt --overwrite
but nothing changed. But I don’t know if this have anything to do it with my lack of log file.
Incidentally, I think logging to a file should be the default setting of a program and if someone does not want logging, then this option should be set in Caddyfile.
I am trying to have a log so as to install crowdsec and a bouncer (but this looks way over my level of newbness).
Thanks anyway for help !
N

Hi
I removed completely caddy and then reinstalled it by using the instructions found on you site. Then I enabled it in systemd and I get an error : there is no Caddyfile
I made a Caddyfile then started again, caddy works. But no log (now the access.log file is not even created)… There might be something wrong with my system…
N

Depending on how you removed it, you might need to re-add the line:

ReadWritePaths=/var/log/caddy
1 Like

Hi
Thanks. I removed everything and then added your line

Still no log ! (Note that the ReadWritePaths command is not listed in the github caddy.service file)
thanks anyway; I think I am stucked with “no log”.
N

Why? The more you mess with the system, the harder it is to troubleshoot. I’ve just tried with a fresh install and it writes to file just fine. The systemd file that comes with the standard install is at /lib/systemd/system/caddy.service. Your earlier run of systemctl status caddy shows /etc/systemd/system/caddy.service.

Not really. Logging to std{out,err} with a systemd service means journald/systemd manage the logging data for you rather than having to manage the files.

1 Like

Hi again
Thanks again for trying to help me. Indeed I found out that there is also a caddy.service file in /lib/systemd/system/
I added your line to this file located in /lib/systemd/…, removed the caddy.service that was in the /etc/ folder and restarted caddy (including daemon§reload). The reverse proxy works (I connected from outside my LAN) but still no log !
Other tests I made : the user caddy exists, the access.log file in var/log/caddy has 777 permissions…
Regards

Hi
Some more digging : the /var/log/caddy/access.log is stil empty but some logging is taking place. If I execute
journalctl -f -u caddy
I can see the logs. Why they are not in the access.log file ?
Thanks

Can you now double-check which systemd unit file is currently enabled and which Caddyfile is running?

systemctl status caddy

and validate the Caddyfile in the run command

1 Like

I have only one caddy.service now, which is located in /lib/systemd/system
the systemctl status command gives

caddy.service - Caddy
Loaded: loaded (/lib/systemd/system/caddy.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2022-01-16 11:39:01 CET; 9h ago
Docs: Welcome — Caddy Documentation
Main PID: 2149104 (caddy)
Tasks: 18 (limit: 38256)
Memory: 9.6M
CGroup: /system.slice/caddy.service
└─2149104 /usr/bin/caddy run --environ --config /etc/caddy/Caddyfile

The caddy.service calls /etc/caddy/Caddyfile
in this Caddyfile I have the log directive.
Is maybe related to the fact that I have a warning at line 11 in my Caddyfile ? (11 is the line that starts with log). I done caddy fmt --overwrite, still I get this waning
Thanks

No, that should be harmless.

Honestly, at this point I’d recommend starting fresh from a clean linux install. It’s hard to help when you may have made all kinds of changes that have deviated from the standard installation.

2 Likes

Hi
Thanks for trying to help. I understand that my system is messy, but I have so many things on it… I will leave it like this for now. At least caddy works even though it is writing the logs in another file.
Regards

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