logging: Fix skip_hosts
with wildcards
#5102
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix #4859
See #4859 (comment) for an explanation of the bug.
The fix was simple, really, we just need to reorder the loops in
server.go
to return true early if a logger is explicitly configured for a hostname.While testing it though, I noticed that there's a bug in the Caddyfile adapter when using the
log
directive with no options (i.e. log to the default logger); it wasn't adding those hosts to thelogger_names
config, so the wildcardskip_hosts
would still cause that to get skipped when it was explicitly configured to log.Basically, I removed some code because it was trying to be "too smart" with omitting some config in the output JSON for "cleanliness" but that just causes edgecase bugs.
Also a side benefit is that logger checks should be slightly faster now (like... nanoseconds at best) because we check a map in
O(1)
before looping overskip_hosts
which isO(n)
.Also set up a const in the
caddy
package for the default logger name, because we use that in lots of places.