httpcaddyfile: Remove port from logger names (#5881)

Co-authored-by: Matt Holt <mholt@users.noreply.github.com>
This commit is contained in:
Francis Lavoie 2023-10-17 01:57:03 -04:00 committed by Matthew Holt
parent 648207063e
commit f0ea489d89
5 changed files with 49 additions and 5 deletions

View File

@ -17,6 +17,7 @@ package httpcaddyfile
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"net"
"reflect" "reflect"
"sort" "sort"
"strconv" "strconv"
@ -797,7 +798,12 @@ func (st *ServerType) serversFromPairings(
if srv.Logs.LoggerNames == nil { if srv.Logs.LoggerNames == nil {
srv.Logs.LoggerNames = make(map[string]string) 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
} }
} }
} }

View File

@ -99,7 +99,7 @@ http://localhost:2020 {
}, },
"logs": { "logs": {
"logger_names": { "logger_names": {
"localhost:2020": "" "localhost": ""
}, },
"skip_unmapped_hosts": true "skip_unmapped_hosts": true
} }

View File

@ -8,6 +8,12 @@
output file /baz.txt output file /baz.txt
} }
} }
example.com:8443 {
log {
output file /port.txt
}
}
---------- ----------
{ {
"logging": { "logging": {
@ -15,7 +21,8 @@
"default": { "default": {
"exclude": [ "exclude": [
"http.log.access.log0", "http.log.access.log0",
"http.log.access.log1" "http.log.access.log1",
"http.log.access.log2"
] ]
}, },
"log0": { "log0": {
@ -35,6 +42,15 @@
"include": [ "include": [
"http.log.access.log1" "http.log.access.log1"
] ]
},
"log2": {
"writer": {
"filename": "/port.txt",
"output": "file"
},
"include": [
"http.log.access.log2"
]
} }
} }
}, },
@ -64,6 +80,28 @@
"foo.example.com": "log0" "foo.example.com": "log0"
} }
} }
},
"srv1": {
"listen": [
":8443"
],
"routes": [
{
"match": [
{
"host": [
"example.com"
]
}
],
"terminal": true
}
],
"logs": {
"logger_names": {
"example.com": "log2"
}
}
} }
} }
} }

View File

@ -76,7 +76,7 @@ http://localhost:8881 {
}, },
"logs": { "logs": {
"logger_names": { "logger_names": {
"localhost:8881": "foo" "localhost": "foo"
} }
} }
} }

View File

@ -81,7 +81,7 @@ http://localhost:8881 {
}, },
"logs": { "logs": {
"logger_names": { "logger_names": {
"localhost:8881": "foo" "localhost": "foo"
} }
} }
} }