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

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(" - ")