Add http headers to trace log

This commit is contained in:
Deluan 2024-06-16 22:25:25 -04:00
parent 88eac6d7f3
commit 4044642abf
3 changed files with 14 additions and 5 deletions

View file

@ -3,6 +3,7 @@ package server
import (
"cmp"
"context"
"encoding/json"
"errors"
"fmt"
"io/fs"
@ -42,7 +43,10 @@ func requestLogger(next http.Handler) http.Handler {
"httpStatus", ww.Status(),
"responseSize", ww.BytesWritten(),
}
if log.IsGreaterOrEqualTo(log.LevelDebug) {
if log.IsGreaterOrEqualTo(log.LevelTrace) {
headers, _ := json.Marshal(r.Header)
logArgs = append(logArgs, "header", string(headers))
} else if log.IsGreaterOrEqualTo(log.LevelDebug) {
logArgs = append(logArgs, "userAgent", r.UserAgent())
}