diff options
author | Frederik Ring <frederik.ring@gmail.com> | 2021-08-02 22:15:27 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-02 14:15:27 -0600 |
commit | 569ecdbd02a3bdf8589f785cca022240973dea4d (patch) | |
tree | c86354c75c0c8b608ee7f06a345ae968a21d405f /caddyconfig/httpcaddyfile | |
parent | c131339c5cda3a541223fde4a714aab55de13b9a (diff) |
httpcaddyfile: Ensure hosts to skip for logs can always be collected (#4258)
* httpcaddyfile: ensure hosts to skip can always be collected
Previously, some hosts that should be skipped in logging would
be missed as the current logic would only collect them after
encountering the first server that would log. This change makes sure
the ServerLogConfig is initialized before iterating over the server
blocks.
* httpcaddyfile: add test case for skip hosts behavior
Diffstat (limited to 'caddyconfig/httpcaddyfile')
-rw-r--r-- | caddyconfig/httpcaddyfile/httptype.go | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/caddyconfig/httpcaddyfile/httptype.go b/caddyconfig/httpcaddyfile/httptype.go index 559d7b7..2a11f85 100644 --- a/caddyconfig/httpcaddyfile/httptype.go +++ b/caddyconfig/httpcaddyfile/httptype.go @@ -522,6 +522,16 @@ func (st *ServerType) serversFromPairings( } } + // if needed, the ServerLogConfig is initialized beforehand so + // that all server blocks can populate it with data, even when not + // coming with a log directive + for _, sblock := range p.serverBlocks { + if len(sblock.pile["custom_log"]) != 0 { + srv.Logs = new(caddyhttp.ServerLogConfig) + break + } + } + // create a subroute for each site in the server block for _, sblock := range p.serverBlocks { matcherSetsEnc, err := st.compileEncodedMatcherSets(sblock) @@ -636,9 +646,6 @@ func (st *ServerType) serversFromPairings( sblockLogHosts := sblock.hostsFromKeys(true) for _, cval := range sblock.pile["custom_log"] { ncl := cval.Value.(namedCustomLog) - if srv.Logs == nil { - srv.Logs = new(caddyhttp.ServerLogConfig) - } if sblock.hasHostCatchAllKey() { // all requests for hosts not able to be listed should use // this log because it's a catch-all-hosts server block |