Can I have multiple logfiles for one host?

1. Caddy version (caddy version):

v2.4.6

2. How I run Caddy:

Windows executable on a Windows Server run by Task Scheduler

a. System environment:

Windows Server 2012

b. Command:

caddy.exe run

d. My complete Caddyfile or JSON config:

http://localhost:80 {
    redir * https://{host}{uri}
    log {
        output file caddy2_http_access_common.log {
            roll_size 10mb
            roll_keep 100
            roll_keep_for 336h
        }
        format single_field common_log
    }
    log {
        output file caddy2_http_access_json.log {
            roll_size 10mb
            roll_keep 100
            roll_keep_for 336h
        }
        format filter {
            wrap json
            fields {
                request>headers>Cookie delete
                resp_headers>Set-Cookie delete
            }
        }
    }
}

3. The problem I’m having:

I want to have two log files, but I only get one (the second/json one).

4. Error messages and/or full log output:

none

5. What I already tried:

http://localhost:80 {
    redir * https://{host}{uri}
    log {
        output file caddy2_http_access_common.log {
            roll_size 10mb
            roll_keep 100
            roll_keep_for 336h
        }
        format single_field common_log

        output file caddy2_http_access_json.log {
            roll_size 10mb
            roll_keep 100
            roll_keep_for 336h
        }
        format filter {
            wrap json
            fields {
                request>headers>Cookie delete
                resp_headers>Set-Cookie delete
            }
        }
    }
}

Documentation says “The log directive applies to the host/port of the site block it appears in”.
If I understand this correctly, there can only be one log directive per host/port and thus only one logfile?
Is there a way I can have two?

FYI, this field will be removed in the next version, v2.5.0. So it’s best not to depend on it. Your logs should mention that it’s deprecated, at startup.

The alternative is to use this plugin: GitHub - caddyserver/transform-encoder: Log encoder module for custom log formats

I think there is a way to do this, but it would involve using the log global option, and it likely wouldn’t support having different files if you have multiple site blocks. I’ll have to do a bit of experimentation myself to see how to make it work. I’ll try to get back to you soon.

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