Skip to content

Commit ac1f20b

Browse files
francislavoiemholt
andauthored
httpcaddyfile: Remove port from logger names (#5881)
Co-authored-by: Matt Holt <[email protected]>
1 parent 174c19a commit ac1f20b

File tree

5 files changed

+49
-5
lines changed

5 files changed

+49
-5
lines changed

caddyconfig/httpcaddyfile/httptype.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package httpcaddyfile
1717
import (
1818
"encoding/json"
1919
"fmt"
20+
"net"
2021
"reflect"
2122
"sort"
2223
"strconv"
@@ -797,7 +798,12 @@ func (st *ServerType) serversFromPairings(
797798
if srv.Logs.LoggerNames == nil {
798799
srv.Logs.LoggerNames = make(map[string]string)
799800
}
800-
srv.Logs.LoggerNames[h] = ncl.name
801+
// strip the port from the host, if any
802+
host, _, err := net.SplitHostPort(h)
803+
if err != nil {
804+
host = h
805+
}
806+
srv.Logs.LoggerNames[host] = ncl.name
801807
}
802808
}
803809
}

caddytest/integration/caddyfile_adapt/log_except_catchall_blocks.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ http://localhost:2020 {
9999
},
100100
"logs": {
101101
"logger_names": {
102-
"localhost:2020": ""
102+
"localhost": ""
103103
},
104104
"skip_unmapped_hosts": true
105105
}

caddytest/integration/caddyfile_adapt/log_override_hostname.txt

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,21 @@
88
output file /baz.txt
99
}
1010
}
11+
12+
example.com:8443 {
13+
log {
14+
output file /port.txt
15+
}
16+
}
1117
----------
1218
{
1319
"logging": {
1420
"logs": {
1521
"default": {
1622
"exclude": [
1723
"http.log.access.log0",
18-
"http.log.access.log1"
24+
"http.log.access.log1",
25+
"http.log.access.log2"
1926
]
2027
},
2128
"log0": {
@@ -35,6 +42,15 @@
3542
"include": [
3643
"http.log.access.log1"
3744
]
45+
},
46+
"log2": {
47+
"writer": {
48+
"filename": "/port.txt",
49+
"output": "file"
50+
},
51+
"include": [
52+
"http.log.access.log2"
53+
]
3854
}
3955
}
4056
},
@@ -64,6 +80,28 @@
6480
"foo.example.com": "log0"
6581
}
6682
}
83+
},
84+
"srv1": {
85+
"listen": [
86+
":8443"
87+
],
88+
"routes": [
89+
{
90+
"match": [
91+
{
92+
"host": [
93+
"example.com"
94+
]
95+
}
96+
],
97+
"terminal": true
98+
}
99+
],
100+
"logs": {
101+
"logger_names": {
102+
"example.com": "log2"
103+
}
104+
}
67105
}
68106
}
69107
}

caddytest/integration/caddyfile_adapt/log_override_name_multiaccess.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ http://localhost:8881 {
7676
},
7777
"logs": {
7878
"logger_names": {
79-
"localhost:8881": "foo"
79+
"localhost": "foo"
8080
}
8181
}
8282
}

caddytest/integration/caddyfile_adapt/log_override_name_multiaccess_debug.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ http://localhost:8881 {
8181
},
8282
"logs": {
8383
"logger_names": {
84-
"localhost:8881": "foo"
84+
"localhost": "foo"
8585
}
8686
}
8787
}

0 commit comments

Comments
 (0)