Changing log location

1. The problem I’m having:

I want to store logs in a different folder than default. So I have this simple test:

http://localhost {
    root /srv/http
    file_server
    log {
        output file /var/log/caddy/localhost.access.log
    }
}

This works fine. Log file is created in the stated (default) location:

LANG=C sudo ls -al /var/log/caddy
total 12
drwxr-x---  2 caddy caddy 4096 Aug 29 13:53 .
drwxr-xr-x 19 root  root  4096 Aug 29 13:49 ..
-rw-------  1 caddy caddy    0 Aug 29 13:53 localhost.access.log

I create another log folder. Directory is owned by Caddy itself and has the same permissions than original log folder:

> LANG=C sudo ls -al /var/log/other
total 12
drwxr-x---  2 caddy caddy 4096 Aug 29 13:30 .
drwxr-xr-x 19 root  root  4096 Aug 29 13:49 ..

I change the location of the log file to the new location (just caddyother):

...
    output file /var/log/other/localhost.access.log
...

But now Caddy refuses to start giving a “read only filesystem” error (error bellow).

Is this a bug? If not I don’t see what I can be doing wrong (and being me it could be very silly, for sure … :slight_smile: )

2. Error messages and/or full log output:

Error: setting up custom log 'log0': opening log writer using &logging.FileWriter{Filename:"/var/log/other/localhost.access.log", Mode:0x0, Roll:(*bool)(nil), RollSizeMB:0, RollCompress:(*bool)(nil), RollLocalTime:false, RollKeep:0, RollKeepDays:0}: open /var/log/other/localhost.access.log: read-only file system

3. Caddy version:

Caddy v2.10.0

4. How I installed and ran Caddy:

a. System environment:

Up to date Manjaro (Arch based).

b. Command:

Caddy is run as a systemd service

You haven’t shared your systemd unit file for caddy, I’m guessing you have a very restrictive ProtectSystem setting, which is OK, but you haven’t adjusted ReadWritePaths to include your new log directory.

Check your systemd settings for Caddy:

systemctl show caddy | grep -E 'Protect|ReadWritePaths'

Hi @Time_Lord, thank you very much for your answer. You seem to be right. It didn’t came to my mind that it could be in the SystemD service, but alas, there it was:

ReadWritePaths=/var/lib/caddy /var/log/caddy /run/caddy

(It’s the default that comes with Arch/Manjaro. I didn’t have seen it until now)

I haven’t tested it yet, but I’m sure that it’s that :slight_smile:

1 Like

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