summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrancis Lavoie <lavofr@gmail.com>2022-04-28 12:16:25 -0400
committerGitHub <noreply@github.com>2022-04-28 12:16:25 -0400
commitaf7321511c960120d61cfd22e031f43071d5a9c2 (patch)
treef7206815dab06fb86b96ba9b0372d4c3aa303973
parent0be3d995439245e8b4069fd3bddcd4b8ef9194d4 (diff)
httpcaddyfile: Fix duplicate access log when debug is on (#4746)
-rw-r--r--caddyconfig/httpcaddyfile/httptype.go18
-rw-r--r--caddytest/integration/caddyfile_adapt/global_options_debug_with_access_log.txt45
2 files changed, 55 insertions, 8 deletions
diff --git a/caddyconfig/httpcaddyfile/httptype.go b/caddyconfig/httpcaddyfile/httptype.go
index 5b0d845..242f0b8 100644
--- a/caddyconfig/httpcaddyfile/httptype.go
+++ b/caddyconfig/httpcaddyfile/httptype.go
@@ -254,20 +254,13 @@ func (st ServerType) Setup(inputServerBlocks []caddyfile.ServerBlock,
}
customLogs = append(customLogs, ncl)
}
+
// Apply global log options, when set
if options["log"] != nil {
for _, logValue := range options["log"].([]ConfigValue) {
addCustomLog(logValue.Value.(namedCustomLog))
}
}
- // Apply server-specific log options
- for _, p := range pairings {
- for _, sb := range p.serverBlocks {
- for _, clVal := range sb.pile["custom_log"] {
- addCustomLog(clVal.Value.(namedCustomLog))
- }
- }
- }
if !hasDefaultLog {
// if the default log was not customized, ensure we
@@ -280,6 +273,15 @@ func (st ServerType) Setup(inputServerBlocks []caddyfile.ServerBlock,
}
}
+ // Apply server-specific log options
+ for _, p := range pairings {
+ for _, sb := range p.serverBlocks {
+ for _, clVal := range sb.pile["custom_log"] {
+ addCustomLog(clVal.Value.(namedCustomLog))
+ }
+ }
+ }
+
// annnd the top-level config, then we're done!
cfg := &caddy.Config{AppsRaw: make(caddy.ModuleMap)}
diff --git a/caddytest/integration/caddyfile_adapt/global_options_debug_with_access_log.txt b/caddytest/integration/caddyfile_adapt/global_options_debug_with_access_log.txt
new file mode 100644
index 0000000..772cd08
--- /dev/null
+++ b/caddytest/integration/caddyfile_adapt/global_options_debug_with_access_log.txt
@@ -0,0 +1,45 @@
+{
+ debug
+}
+
+:8881 {
+ log {
+ format console
+ }
+}
+----------
+{
+ "logging": {
+ "logs": {
+ "default": {
+ "level": "DEBUG",
+ "exclude": [
+ "http.log.access.log0"
+ ]
+ },
+ "log0": {
+ "encoder": {
+ "format": "console"
+ },
+ "level": "DEBUG",
+ "include": [
+ "http.log.access.log0"
+ ]
+ }
+ }
+ },
+ "apps": {
+ "http": {
+ "servers": {
+ "srv0": {
+ "listen": [
+ ":8881"
+ ],
+ "logs": {
+ "default_logger_name": "log0"
+ }
+ }
+ }
+ }
+ }
+} \ No newline at end of file