Caddy docker-compose getting module named 'caddy.logging.encoders.single_field': module not registered

Hi folks. Hope everyone is doing well :wink:
Caddy looks tremendously nice
Thanks to all the community !
i’m totally noob with the CaddyFile syntax and basics if someone can give me some hint i wold be grateful. thank you .

1. The problem I’m having:

I try to deploy a very simple caddy server with docker-compose. It works like charm but i need to produce logs (access.log) .

then need to transform my access.log to be readable by goaccess

If i understand correctly i need at least one external module :

caddy.logging.encoders.json

i really want to keep things simple and don’t want to compile via xcaddy.

My question is how can i achieve this very simple puprose or writing logs somewhere ?

i can’t find logs in data/acces.logs

2. Error messages and/or full log output:

{"level":"info","ts":1705715576.5076275,"msg":"using provided configuration","config_file":"/etc/caddy/Caddyfile","config_adapter":"caddyfile"}
Error: adapting config using caddyfile: parsing caddyfile tokens for 'log': getting module named 'caddy.logging.writers.data/access.log': module not registered: caddy.logging.writers.data/access.log, at /etc/caddy/Caddyfile:10

3. Caddy version:

v2.7.6 h1

4. How I installed and ran Caddy:

via docker compose

a. System environment:

rocky 9 with podman.

b. Command:

podman-compose up -d

c. Service/unit/compose file:

version: "3.9"

services:
  caddy:
    image: caddy:latest
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
      - "443:443/udp"
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile
      - ./site:/var/www/html
      - caddy_data:/data
      - caddy_config:/config
    depends_on:
      - webdav
volumes:
  caddy_data:
  caddy_config:

d. My complete Caddy config:

my.super.domain {
        # Set webroot
        root * /var/www/html
        # enable compression
        encode zstd gzip
        # Enable the static file server.
        file_server
        # enable log for goaccess
        log default {
        output data/access.log
        format json
        }
}

5. Links to relevant resources:

single_field no longer exists. It’s was deprecated a couple years ago, and removed about a year later.

This is invalid syntax, the output option takes a module name as the first argument, for example file and then file takes arguments, i.e. a file name.

See the docs: log (Caddyfile directive) — Caddy Documentation

Thanks for your answer. I’m really uncomforatble with the syntax. so is this syntax ok ?

my.super.domainame{
        # Set webroot
        root * /var/www/html
        # enable compression
        encode zstd gzip
        # Enable the static file server.
        file_server
        # enable log for goaccess
        log default {
        output file data/access.log {
                }
        }
}

You must have a space between your domain and the {

The indentation is weird, you should tab in the output line another step.

Also, you can remove the inner { } after the filename because you’re not providing any options to the file writer.

You can run caddy fmt -w <path-to-your-Caddyfile> to clean up the syntax.

IMO the comments you have are not that useful, they state the obvious.

Thank you for you suggestions and explanations.

I end-up with this conf working like a charm :

my.super.domain {
    root * /var/www/html
    encode zstd gzip
    file_server
    log {
        output file data/access.log {
            format json
            roll_local_time
            roll_keep     10
            roll_keep_for 365d
        }
    }
}
1 Like

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