Caddyfile logging

1. Caddy version (caddy version):

v2.3.0

2. How I run Caddy:

I want to run Caddy as a sidecar container to Hugo

a. System environment:

Docker

b. Command:

caddy run --config /config/caddy-conf

d. My complete Caddyfile or JSON config:

    {
      "logging": {
       "log": {
         "output": "file",
         "filename": "access.log",
         "roll_size_mb": 20,
         "level": "DEBUG"
        }
      }
    }

3. The problem I’m having:

I want to run Caddy mainly as a log emitter, so I’ve been experimenting with configs (one of the examples is above, but I also tried some other options). However, I feel like documentation is not too clear on that and I keep running into different error messages regarding the parsing of my config. Maybe it’s a bit of a noob question, and I’m sorry if it is, but I’m desperate. My goal is only to get logs from a site served by Hugo. I’ve had experience with Nginx as a sidecar container before but wanted to try out Caddy. The goal is: get access logs as pages visited, searches performed, maybe load time of pages (if possible), so mostly around the usage of the site. Thank you in advance.

4. Error messages and/or full log output:

run: loading initial config: loading new config: json: unknown field "log"

5. What I already tried:

I’ve seen some other options like

    {
      log {
        level debug
      }
    }

just debug and some other replacement and playing around with spacing, newlines, format, etc.

6. Links to relevant resources:

Hi

This is Caddyfile is working for me, logging access. Notice that logging is per domain, and not “globally”.

:80  { 
        log {
                output file /tmp/acces.log {
                }
        }
        reverse_proxy {
			to 185.52.1.16:8080
        }
}

1 Like

Note that it will be possible to configure logging globally as of v2.4, but that’s correct.

I’m unclear on what you’re actually trying to do here. You seem to only be giving us a small part of your config, which is not useful when trying to give help. Please give us the full picture here.

1 Like

Hey, thanks for the reply.
So, I’m trying to run Caddy as a sidecar container to Hugo, playing the role of a log emitter. My site is served with the hugo serve command. My assumption is that, in this case, the only thing I need to write in my Caddyfile is log config, as my site is served by Hugo, and port config comes in pod.yml. Should I still specify something in a Caddyfile to make it work?

I don’t really understand what you mean by “log emitter”. Caddy can only write logs for services it’s serving. It can’t magically intercept connections or whatever.

What you probably want to do is have Caddy accept the connection, then proxy to your hugo service.

1 Like

Got the idea, thank you :slight_smile: I must’ve misunderstood the concept of sidecar container.

1 Like

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