Skip to content

Commit

Permalink
use Response-Status-Code if given
Browse files Browse the repository at this point in the history
  • Loading branch information
vkuznet committed Jul 11, 2024
1 parent 5a02123 commit 6c486c7
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@ func LogRequest(w http.ResponseWriter, r *http.Request, start time.Time, cauth s
refMsg := fmt.Sprintf("[ref: \"%v\" \"%v\"]", ref, r.Header.Get("User-Agent"))
respTime := "0"
if respHeader.Get("Response-Time") != "" {
// respTime = fmt.Sprintf("%s", respHeader.Get("Response-Time"))
if seconds, err := parseHumanReadableTime(respHeader.Get("Response-Time")); err == nil {
respTime = fmt.Sprintf("%f", seconds)
}
Expand All @@ -273,8 +272,15 @@ func LogRequest(w http.ResponseWriter, r *http.Request, start time.Time, cauth s
if err != nil {
uri = r.RequestURI
}
log.Printf("%s %d %s %s %s %s %s %s %s\n", r.Proto, *status, r.Method, uri, dataMsg, addr, authMsg, refMsg, respMsg)
// log.Printf("%s %s %s %s %d %s %s %s %s\n", addr, r.Method, uri, r.Proto, *status, dataMsg, authMsg, refMsg, respMsg)
statusCode := *status
if len(w.Header()["Response-Status-Code"]) > 0 {
// if status code was set by reverse proxy
scode := w.Header()["Response-Status-Code"][0]
if c, err := strconv.Atoi(scode); err == nil {
statusCode = c
}
}
log.Printf("%s %d %s %s %s %s %s %s %s\n", r.Proto, statusCode, r.Method, uri, dataMsg, addr, authMsg, refMsg, respMsg)
if CMSMonitType == "" || CMSMonitProducer == "" {
return
}
Expand Down

0 comments on commit 6c486c7

Please sign in to comment.