Change file mask for caddy log files

Hi there,

currently using this Caddyfile for a little research project. Everything works good so far and I’m happy with the caddy webserver.

# Caddy configuration file

:80 {
        root * /usr/share/caddy/80
        file_server
        log port-80 {
                output file /var/log/caddy/80-caddy.log {
                        roll_uncompressed
                        roll_local_time
                        roll_keep 20
                        roll_keep_for 365d
                }
                format json {
                        time_format wall
                        time_local
                }
        }
}

:8080 {
        root * /usr/share/caddy/8080
        redir / /devfileshare
        file_server browse
        log port-8080 {
                output file /var/log/caddy/8080-caddy.log {
                        roll_uncompressed
                        roll_local_time
                        roll_keep 20
                        roll_keep_for 365d
                }
                format json {
                        time_format wall
                        time_local
                }
        }
}
}

Now I got a question regarding the file permissions of the logfiles.
We got a need to change the file rights to 640 (rw-r-----) instead of the default 600 (rw-------).

user: /var/log/caddy$ ls -lah
total 36K
drwxr-xr-x 2 caddy caddy 4.0K Jan 30 15:20 .
drwxr-xr-x 9 root  root  4.0K Jan 30 00:00 ..
-rw------- 1 caddy caddy  17K Jan 30 15:37 8080-caddy.log
-rw------- 1 caddy caddy 6.4K Jan 30 15:37 8443-caddy.log

If I change the rights with the following command the caddy webserver log in the file without any problem.

user: /var/log/caddy$ sudo chmod 640 /var/log/caddy/*.log
user: /var/log/caddy$ ls -lah
total 36K
drwxr-xr-x 2 caddy caddy 4.0K Jan 30 15:20 .
drwxr-xr-x 9 root  root  4.0K Jan 30 00:00 ..
-rw-r----- 1 caddy caddy  17K Jan 30 15:37 8080-caddy.log
-rw-r----- 1 caddy caddy 6.4K Jan 30 15:37 8443-caddy.log

But when the logfiles get deleted (by hand) and created again by the caddy webserver the file rights are still the same. Of course…

user: /var/log/caddy$ ls -lah
total 36K
drwxr-xr-x 2 caddy caddy 4.0K Jan 30 15:20 .
drwxr-xr-x 9 root  root  4.0K Jan 30 00:00 ..
-rw------- 1 caddy caddy  13K Jan 30 15:40 8080-caddy.log
-rw------- 1 caddy caddy 68K Jan 30 15:40 8443-caddy.log

I just wanted to ask if it is possible to change the default file mask of caddy log files? Could not find anything about this in the docs.

Many thanks,

Unfortunately the library we’re using in Caddy for the file writer doesn’t support this yet. See Can support custom file permissions? · Issue #164 · natefinch/lumberjack · GitHub

@francislavoie thanks for your fast answer and clarification on this issue.
Would be nice if this library supports this feature in the near future!

Unfortunately the library has fallen out of maintenance, so don’t get your hopes up.

We’ve thought about forking it for our own needs, but we don’t really have the time to maintain another project. If someone is willing to take on that responsibility though, we’d gladly switch over to it (as long as it’s reasonably compatible and a mostly drop-in replacement).

2 Likes

Thanks again for the info and the call to the community! Sorry but I can’t fill this task.

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