bump go-pkgz/rest to show hostname in stdout logs

This commit is contained in:
Umputun 2021-04-17 12:46:22 -05:00
parent 0a9051d528
commit 401375b8d7
4 changed files with 13 additions and 4 deletions

2
go.mod
View File

@ -5,7 +5,7 @@ go 1.16
require (
github.com/BurntSushi/toml v0.3.1 // indirect
github.com/go-pkgz/lgr v0.10.4
github.com/go-pkgz/rest v1.9.1
github.com/go-pkgz/rest v1.9.2
github.com/gorilla/handlers v1.5.1
github.com/stretchr/testify v1.7.0
github.com/umputun/go-flags v1.5.1

2
go.sum
View File

@ -8,6 +8,8 @@ github.com/go-pkgz/lgr v0.10.4 h1:l7qyFjqEZgwRgaQQSEp6tve4A3OU80VrfzpvtEX8ngw=
github.com/go-pkgz/lgr v0.10.4/go.mod h1:CD0s1z6EFpIUplV067gitF77tn25JItzwHNKAPqeCF0=
github.com/go-pkgz/rest v1.9.1 h1:JW876BgJJ/MOkAYRnnzpfX7xUqIav+ou1LSVTtQq/Lo=
github.com/go-pkgz/rest v1.9.1/go.mod h1:wZ/dGipZUaF9to0vIQl7PwDHgWQDB0jsrFg1xnAKLDw=
github.com/go-pkgz/rest v1.9.2 h1:RyBBRXBYY6eBgTW3UGYOyT4VQPDiBBFh/tesELWsryQ=
github.com/go-pkgz/rest v1.9.2/go.mod h1:wZ/dGipZUaF9to0vIQl7PwDHgWQDB0jsrFg1xnAKLDw=
github.com/gorilla/handlers v1.5.1 h1:9lRY6j8DEeeBT10CvO9hGW0gmky0BprnvDI5vfhUHH4=
github.com/gorilla/handlers v1.5.1/go.mod h1:t8XrUpc4KVXb7HGyJ4/cEnwQiaxrX/hz1Zv/4g96P1Q=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=

View File

@ -41,6 +41,7 @@ type logParts struct {
remoteIP string
statusCode int
respSize int
host string
prefix string
user string
@ -108,10 +109,16 @@ func (l *Middleware) Handler(next http.Handler) http.Handler {
remoteIP = l.ipFn(remoteIP)
}
server := r.URL.Hostname()
if server == "" {
server = strings.Split(r.Host, ":")[0]
}
p := &logParts{
duration: t2.Sub(t1),
rawURL: rawurl,
method: r.Method,
host: server,
remoteIP: remoteIP,
statusCode: ww.status,
respSize: ww.size,
@ -135,8 +142,8 @@ func (l *Middleware) formatDefault(r *http.Request, p *logParts) string {
_, _ = bld.WriteString(" ")
}
_, _ = bld.WriteString(fmt.Sprintf("%s - %s - %s - %d (%d) - %v",
p.method, p.rawURL, p.remoteIP, p.statusCode, p.respSize, p.duration))
_, _ = bld.WriteString(fmt.Sprintf("%s - %s - %s - %s - %d (%d) - %v",
p.method, p.rawURL, p.host, p.remoteIP, p.statusCode, p.respSize, p.duration))
if p.user != "" {
_, _ = bld.WriteString(" - ")

2
vendor/modules.txt vendored
View File

@ -7,7 +7,7 @@ github.com/felixge/httpsnoop
# github.com/go-pkgz/lgr v0.10.4
## explicit
github.com/go-pkgz/lgr
# github.com/go-pkgz/rest v1.9.1
# github.com/go-pkgz/rest v1.9.2
## explicit
github.com/go-pkgz/rest
github.com/go-pkgz/rest/logger