Set log filename = hostname?

1. Caddy version (caddy version):

v2.2.1 h1:Q62GWHMtztnvyRU+KPOpw6fNfeCD3SkwH7SfT1Tgt2c=

2. How I run Caddy:

a. System environment:

MacOS 10.15.7

b. Command:

installed with brew. So :

brew services start caddy
or 
caddy reload --config /usr/local/etc/Caddyfile

c. My complete Caddyfile or JSON config:

not the complete file, but the logging part of my snippet

(app) {

    *.{args.0}, {args.0} {

        log {
            
            ## {args.0} do work
            output file /var/logs/{args.0}.log

            ## this one {http.request.host} do NOT work
            ## output file /var/logs/{http.request.host}.log
        }
    }

}



then, in my main config file, I have several call to this snippet :

import app website1.com
import app website2.com
etc...

3. The problem I’m having:

I’m using a snippet for most of my sites. Very nice. But I’m not able to specify the name of the hostname in the log filename. I’m only able to use the parameters used in my snippet.

This one works :

output file /var/logs/{args.0}.log

This one DO NOT works :

output file /var/logs/{http.request.host}.log

So, when I have subdomain, I’m not able to have on log file per subdomain.

If I have www.website1.com and private.website1.com, I can only log in website1.com.log ; but I would like to log to www.website.com.log and private.website1.com.log

Am I mising something ? By advance, thank !

Request placeholders can’t be used for log filrnames, because logging involves setting up a file handle that is open long-term, across the lifetime of the server.

Caddyfile import args work because those are evaluated immediately at startup time (Caddyfile adapt time to be precise).

Not to mention that leaves your server open to inode depletion attacks.

1 Like

Thank you for your quick answer!

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