Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

httpcaddyfile: Remove port from logger names #5881

Merged
merged 2 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion caddyconfig/httpcaddyfile/httptype.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package httpcaddyfile
import (
"encoding/json"
"fmt"
"net"
"reflect"
"sort"
"strconv"
Expand Down Expand Up @@ -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
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ http://localhost:2020 {
},
"logs": {
"logger_names": {
"localhost:2020": ""
"localhost": ""
},
"skip_unmapped_hosts": true
}
Expand Down
40 changes: 39 additions & 1 deletion caddytest/integration/caddyfile_adapt/log_override_hostname.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,21 @@
output file /baz.txt
}
}

example.com:8443 {
log {
output file /port.txt
}
}
----------
{
"logging": {
"logs": {
"default": {
"exclude": [
"http.log.access.log0",
"http.log.access.log1"
"http.log.access.log1",
"http.log.access.log2"
]
},
"log0": {
Expand All @@ -35,6 +42,15 @@
"include": [
"http.log.access.log1"
]
},
"log2": {
"writer": {
"filename": "/port.txt",
"output": "file"
},
"include": [
"http.log.access.log2"
]
}
}
},
Expand Down Expand Up @@ -64,6 +80,28 @@
"foo.example.com": "log0"
}
}
},
"srv1": {
"listen": [
":8443"
],
"routes": [
{
"match": [
{
"host": [
"example.com"
]
}
],
"terminal": true
}
],
"logs": {
"logger_names": {
"example.com": "log2"
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ http://localhost:8881 {
},
"logs": {
"logger_names": {
"localhost:8881": "foo"
"localhost": "foo"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ http://localhost:8881 {
},
"logs": {
"logger_names": {
"localhost:8881": "foo"
"localhost": "foo"
}
}
}
Expand Down