Add request logging to panic recovery #63

Merged
electricdusk merged 1 commits from issue-61 into master 2020-07-06 17:13:03 +02:00
Owner

When a panic occurs in a request, this patch makes sure that some info about the request is logged.

Fixes #61

When a panic occurs in a request, this patch makes sure that some info about the request is logged. Fixes #61
mrngm was assigned by electricdusk 2020-05-30 17:35:44 +02:00
mrngm requested changes 2020-06-28 13:12:52 +02:00
router.go Outdated
@ -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)
Collaborator

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) that http.Request.RemoteAddr is filled using IP:port, so this check should not be necessary.

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) that `http.Request.RemoteAddr` is filled using `IP:port`, so this check should not be necessary.
router.go Outdated
@ -33,0 +37,4 @@
if err != nil {
host = r.RemoteAddr
}
timeDesc := ts.Format("02/Jan/2006:15:04:05 -0700")
Collaborator

log.Printf already registers the timestamp. What's the use of a second timestamp here?

`log.Printf` already registers the timestamp. What's the use of a second timestamp here?
router.go Outdated
@ -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)
Collaborator

Instead of '%s', you may use %q, which automatically quotes the supplied string.

Instead of `'%s'`, you may use `%q`, which automatically quotes the supplied string.
electricdusk closed this pull request 2020-07-06 17:13:03 +02:00
Sign in to join this conversation.
No reviewers
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: electricdusk/rushlink#63
No description provided.