Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 12, 22:00 UTC
httpcaddyfile: Remove port from logger names (#5881)
Co-authored-by: Matt Holt <mholt@users.noreply.github.com>
Francis Lavoie committed
Oct 17, 2023 at 01:57 UTC
ac1f20b9e470425c1a67939d37883c03175bd827
5 files changed
+49
-5
caddyconfig/httpcaddyfile/httptype.go
+7
-1
@@ -17,6 +17,7 @@ package httpcaddyfile
17
import (
18
"encoding/json"
19
"fmt"
20
+ "net"
21
"reflect"
22
"sort"
23
"strconv"
@@ -797,7 +798,12 @@ func (st *ServerType) serversFromPairings(
798
if srv.Logs.LoggerNames == nil {
799
srv.Logs.LoggerNames = make(map[string]string)
800
}
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
807
}
808
}
809
}
caddytest/integration/caddyfile_adapt/log_except_catchall_blocks.txt
+1
-1
@@ -99,7 +99,7 @@ http://localhost:2020 {
99
},
100
"logs": {
101
"logger_names": {
102
- "localhost:2020": ""
102
+ "localhost": ""
103
},
104
"skip_unmapped_hosts": true
105
}
caddytest/integration/caddyfile_adapt/log_override_hostname.txt
+39
-1
@@ -8,6 +8,12 @@
8
output file /baz.txt
9
}
10
}
11
+
12
+example.com:8443 {
13
+ log {
14
+ output file /port.txt
15
+ }
16
+}
17
----------
18
{
19
"logging": {
@@ -15,7 +21,8 @@
21
"default": {
22
"exclude": [
23
"http.log.access.log0",
18
- "http.log.access.log1"
24
+ "http.log.access.log1",
25
+ "http.log.access.log2"
26
]
27
},
28
"log0": {
@@ -35,6 +42,15 @@
42
"include": [
43
"http.log.access.log1"
44
]
45
+ },
46
+ "log2": {
47
+ "writer": {
48
+ "filename": "/port.txt",
49
+ "output": "file"
50
+ },
51
+ "include": [
52
+ "http.log.access.log2"
53
+ ]
54
}
55
}
56
},
@@ -64,6 +80,28 @@
80
"foo.example.com": "log0"
81
}
82
}
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
+ }
105
}
106
}
107
}
caddytest/integration/caddyfile_adapt/log_override_name_multiaccess.txt
+1
-1
@@ -76,7 +76,7 @@ http://localhost:8881 {
76
},
77
"logs": {
78
"logger_names": {
79
- "localhost:8881": "foo"
79
+ "localhost": "foo"
80
}
81
}
82
}
caddytest/integration/caddyfile_adapt/log_override_name_multiaccess_debug.txt
+1
-1
@@ -81,7 +81,7 @@ http://localhost:8881 {
81
},
82
"logs": {
83
"logger_names": {
84
- "localhost:8881": "foo"
84
+ "localhost": "foo"
85
}
86
}
87
}