Logging in beta18

1. My Caddy version (caddy version):

v2.0.0-beta.18

2. How I run Caddy:

caddy adapt Caddyfile
sudo caddy run

a. System environment:

RPi 3 @ raspbian
Linux 4.19.97-v7+ #1294 SMP Thu Jan 30 13:15:58 GMT 2020 armv7l GNU/Linux

d. My complete Caddyfile or JSON config:

{
        admin off
        email me@sth.com
}

log
{
        output file /var/log/caddy.txt
        {
                roll_size 10
                roll_keep 3
                roll_keep_for 90
        }
}

test.sth.com
{
        encode zstd gzip
        reverse_proxy 127.0.0.1:8080
} 

3. The problem I’m having:

Trying to get access logs written as per https://caddyserver.com/docs/caddyfile/directives/log#log
And then converting it from caddyfile to json (I prefer the former for quick editing). The conversion doesn’t work, so either I’m placing it wrong, something has changed or, as mentioned in other places, this can’t be done in Caddyfile.
Please be gentle, this is literally my 2nd day with caddy. I’m happy to have it working, but w/o fail2ban on top of it, I’ll soon be flooded :wink:

4. Error messages and/or full log output:

2020/03/23 21:56:06.071 INFO using adjacent Caddyfile
adapt: Caddyfile:8: unrecognized directive: output

5. What I already tried:

moving / nesting the log block in different places, adding more details like format or level.

1 Like

Your Caddyfile should look something like this:

{
    admin off
    email me@sth.com
}

test.sth.com {
    encode zstd gzip
    reverse_proxy 127.0.0.1:8080

    log {
        output file /var/log/caddy.txt {
            roll_size 10
            roll_keep 3
            roll_keep_for 90
        }
    }
} 

See the Caddyfile structure docs: https://caddyserver.com/docs/caddyfile/concepts#structure

The log directive is a standard directive, and all directives appear inside site blocks. The only things outside of them are snippets and the global options block at the start of the file.

1 Like

Thanks a lot for help. Indeed I got rid of the adapt error, still… The log isn’t written to the file specified. I tried different locations and different paths. It’s just not being created.
???

I think the roll_size is wrong. I think you want 10MiB. I think 10 is actually 10 bytes in this case :joy: That might be what’s preventing it from being written altogether.

1 Like

I changed that, but it didn’t help. What’s interesting, adopting the file produces a json with this section:
"logs":{}}}}
Does it mean it simply not getting imported / converted?

ps. Re. the size of logs… It’s funky :wink: In some places the docs says it could be 100MiB, in some other places 1gb; so not clear what’s the valid formatting.

I just confirmed that this log directive:

log {
        output file /var/log/caddy.txt {
            roll_size 10mb
            roll_keep 3
            roll_keep_for 2160h
        }
}

adapts to the correct JSON. Notice the units on the fields. (Durations don’t yet accept days, that’s another feature for another time.)

I’m unable to reproduce this; the Caddyfile above (with my modifications) produces:

"logs": {
      "log0": {
        "writer": {
          "filename": "/var/log/caddy.txt",
          "output": "file",
          "roll_keep": 3,
          "roll_keep_days": 90,
          "roll_size_mb": 10
        },
        "include": [
          "http.log.access.log0"
        ]
      }
    }

It accepts almost any human-readable format: https://pkg.go.dev/github.com/dustin/go-humanize?tab=doc#ParseBytes

OK, I figured it out… This will work:

log {
        output file /var/log/caddy.txt {
            roll_size 10mb
[...]

That will not work:

log
{
        output file /var/log/caddy.txt
        {
            roll_size 10mb
[...]

So the parser is pretty sensitive to what’s going on with {} and new lines. But I have it working now!

2 Likes

Correct, yes: https://caddyserver.com/docs/caddyfile/concepts#blocks

1 Like

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