diff --git a/caddyconfig/httpcaddyfile/httptype.go b/caddyconfig/httpcaddyfile/httptype.go index 3e8fdcac..c82d92ef 100644 --- a/caddyconfig/httpcaddyfile/httptype.go +++ b/caddyconfig/httpcaddyfile/httptype.go @@ -17,6 +17,7 @@ package httpcaddyfile import ( "encoding/json" "fmt" + "net" "reflect" "sort" "strconv" @@ -797,7 +798,12 @@ func (st *ServerType) serversFromPairings( if srv.Logs.LoggerNames == nil { srv.Logs.LoggerNames = make(map[string]string) } - srv.Logs.LoggerNames[h] = ncl.name + // strip the port from the host, if any + host, _, err := net.SplitHostPort(h) + if err != nil { + host = h + } + srv.Logs.LoggerNames[host] = ncl.name } } } diff --git a/caddytest/integration/caddyfile_adapt/log_except_catchall_blocks.txt b/caddytest/integration/caddyfile_adapt/log_except_catchall_blocks.txt index ed3b20de..6fbc6c7c 100644 --- a/caddytest/integration/caddyfile_adapt/log_except_catchall_blocks.txt +++ b/caddytest/integration/caddyfile_adapt/log_except_catchall_blocks.txt @@ -99,7 +99,7 @@ http://localhost:2020 { }, "logs": { "logger_names": { - "localhost:2020": "" + "localhost": "" }, "skip_unmapped_hosts": true } diff --git a/caddytest/integration/caddyfile_adapt/log_override_hostname.txt b/caddytest/integration/caddyfile_adapt/log_override_hostname.txt index 4511fd49..c36ba23f 100644 --- a/caddytest/integration/caddyfile_adapt/log_override_hostname.txt +++ b/caddytest/integration/caddyfile_adapt/log_override_hostname.txt @@ -8,6 +8,12 @@ output file /baz.txt } } + +example.com:8443 { + log { + output file /port.txt + } +} ---------- { "logging": { @@ -15,7 +21,8 @@ "default": { "exclude": [ "http.log.access.log0", - "http.log.access.log1" + "http.log.access.log1", + "http.log.access.log2" ] }, "log0": { @@ -35,6 +42,15 @@ "include": [ "http.log.access.log1" ] + }, + "log2": { + "writer": { + "filename": "/port.txt", + "output": "file" + }, + "include": [ + "http.log.access.log2" + ] } } }, @@ -64,6 +80,28 @@ "foo.example.com": "log0" } } + }, + "srv1": { + "listen": [ + ":8443" + ], + "routes": [ + { + "match": [ + { + "host": [ + "example.com" + ] + } + ], + "terminal": true + } + ], + "logs": { + "logger_names": { + "example.com": "log2" + } + } } } } diff --git a/caddytest/integration/caddyfile_adapt/log_override_name_multiaccess.txt b/caddytest/integration/caddyfile_adapt/log_override_name_multiaccess.txt index a3b0cec6..d48857a2 100644 --- a/caddytest/integration/caddyfile_adapt/log_override_name_multiaccess.txt +++ b/caddytest/integration/caddyfile_adapt/log_override_name_multiaccess.txt @@ -76,7 +76,7 @@ http://localhost:8881 { }, "logs": { "logger_names": { - "localhost:8881": "foo" + "localhost": "foo" } } } diff --git a/caddytest/integration/caddyfile_adapt/log_override_name_multiaccess_debug.txt b/caddytest/integration/caddyfile_adapt/log_override_name_multiaccess_debug.txt index e6698e4f..d024dc38 100644 --- a/caddytest/integration/caddyfile_adapt/log_override_name_multiaccess_debug.txt +++ b/caddytest/integration/caddyfile_adapt/log_override_name_multiaccess_debug.txt @@ -81,7 +81,7 @@ http://localhost:8881 { }, "logs": { "logger_names": { - "localhost:8881": "foo" + "localhost": "foo" } } }