Caddyfile v2 logging directive not working

1. Caddy version (caddy version):

v2.4.3 h1:Y1FaV2N4WO3rBqxSYA8UZsZTQdN+PwcoOcAiZTM8C0I=

2. How I run Caddy:

Running caddy as a caddy user (everything works except when I put logging directive in) on alpine. Using xcaddy to build with custom DNS modules. I can see that the file logging module (writer) is in, but when I put the logging directives in Caddyfile, the validator barfs.

a. System environment:

Linux web01 5.10.59-0-virt #1-Alpine SMP Mon, 16 Aug 2021 09:59:55 +0000 x86_64 Linux

b. Command:

caddy validate

c. Service/unit/compose file:

#!/sbin/openrc-run
supervisor=supervise-daemon

name="Caddy web server"
description="Fast, multi-platform web server with automatic HTTPS"
description_checkconfig="Check configuration"
description_reload="Reload configuration without downtime"

: ${caddy_opts:="--config /etc/caddy/Caddyfile --adapter caddyfile"}

command=/usr/sbin/caddy
command_args="run $caddy_opts"
command_user=caddy:caddy
extra_commands="checkconfig"
extra_started_commands="reload"

depend() {
        need net localmount
        after firewall
}

checkconfig() {
        ebegin "Checking configuration for $name"
        su ${command_user%:*} -s /bin/sh -c "$command validate $caddy_opts"
        eend $?
}

reload() {
        ebegin "Reloading $name"
        su ${command_user%:*} -s /bin/sh -c "$command reload $caddy_opts"
        eend $?
}

stop_pre() {
        if [ "$RC_CMD" = restart ]; then
                checkconfig || return $?
        fi
}

d. My complete Caddyfile or JSON config:

Paste config here, replacing this text.
Use `caddy fmt` to make it readable.
DO NOT REDACT anything except credentials.
LEAVE DOMAIN NAMES INTACT.
Make sure the backticks stay on their own lines.

apps.gocloud.sh {
root * /www
file_server {
precompressed zstd br gzip
}
tls thomas@munn.me
}
log {
output file /home/caddy/logs/caddy.log {
roll_size 100m
roll_keep 7
roll_keep_for 720
}
}

### 3. The problem I'm having:
<!-- What are you trying to do, and what isn't working? Please describe the issue thoroughly enough so that anyone can reproduce the exact behavior you're seeing. Be as specific as possible. DO NOT USE WEB BROWSERS; use "curl -v" instead. -->
The error I get is `validate: adapting config using caddyfile: Caddyfile:9: unrecognized directive: output`
I can't add the logging directive, even though the logging modules seem to be loaded. No matter what I do can't get the logs to work. Caddy modules lists the following:



### 4. Error messages and/or full log output:
<!-- Please **DO NOT REDACT** any information except credentials. Leave domain names intact! -->
<!-- Please **DO NOT POST TRUNCATED LOG LINES** as systemd is notorious for this. -->
<!-- Please **DO NOT USE WEB BROWSERS.** Use curl -v instead. -->
<!-- Please **DO ENABLE DEBUG MODE FIRST** by adding "debug" to the global options of your Caddyfile. -->
Since my caddyfile is invalid, I won't get debug outputs, but its here:
validate: adapting config using caddyfile: Caddyfile:9: unrecognized directive: output

### 5. What I already tried:
<!-- Show us what effort you've put in to solving the problem. Be specific -- people are volunteering their time to help you! Low effort posts are not likely to get good answers! -->

I followed the pages in wiki, added directives as asked, and logging module is either not loaded or won't load.

### 6. Links to relevant resources:

Please try to fix the formatting of your post, it’s very difficult to read.

Make sure that each set of ``` has a matching closing set on their own lines. These are delimiters for code blocks in markdown.

I just used the system supplied one. Seems when you use xcaddy to build yourself, the logging module isn’t included. I was just looking for the xcaddy line to add the logging to the server when building.

No, logging is always included. You must have a syntax error in your config, but your post has broken formatting, so it’s very difficult to read.

Please fix your post’s formatting, as requested.

Please review the docs to understand how the Caddyfile is structured:

Stupid question how do I edit my post?

apps.gocloud.sh {
        root * /www
        file_server {
                precompressed zstd br gzip
        }
        tls go@away.com
        log {
                output file /home/caddy/logs/apps.log {
                        roll_keep 7
                        roll_keep_for 14d
                }
        }
}

its fixed, so I guess we can close this. this one works (I just gave up on my custom binary)

The pencil icon at the bottom of the post.

I’m certain the binary wasn’t the issue, the config was.

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