Add request logging to panic recovery #63
No reviewers
Labels
No Label
bug
feature
good-beginner-bug
needs-test
question
wontfix
No Milestone
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: electricdusk/rushlink#63
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "issue-61"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
When a panic occurs in a request, this patch makes sure that some info about the request is logged.
Fixes #61
@ -32,1 +33,4 @@
ts := time.Now()
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
logRequestInfo := func() {
host, _, err := net.SplitHostPort(r.RemoteAddr)
I don't see a reason why the source port needs to be chopped off. Besides, the
net/http
server guarantees (by means of documentation) thathttp.Request.RemoteAddr
is filled usingIP:port
, so this check should not be necessary.@ -33,0 +37,4 @@
if err != nil {
host = r.RemoteAddr
}
timeDesc := ts.Format("02/Jan/2006:15:04:05 -0700")
log.Printf
already registers the timestamp. What's the use of a second timestamp here?@ -33,0 +38,4 @@
host = r.RemoteAddr
}
timeDesc := ts.Format("02/Jan/2006:15:04:05 -0700")
log.Printf("in request: [%s] %v - %v '%s' %v", timeDesc, host, r.Method, r.RequestURI, r.Proto)
Instead of
'%s'
, you may use%q
, which automatically quotes the supplied string.