Skip to content

Commit

Permalink
Add the status back with more clarity.
Browse files Browse the repository at this point in the history
  • Loading branch information
kylev committed Oct 4, 2024
1 parent 93f64c3 commit af1c602
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion hlog/hlog_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,14 @@ func Example_handler() {

// Here is your final handler
h := c.Then(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
status := http.StatusOK // Your business logic here

// Get the logger from the request's context. You can safely assume it
// will be always there: if the handler is removed, hlog.FromRequest
// will return a no-op logger.
hlog.FromRequest(r).Info().
Str("user", "current user").
Int("status", status).
Msg("Something happened")
}))

Expand All @@ -73,5 +76,5 @@ func Example_handler() {
panic("http.Get failed")
}

// Output: {"level":"info","role":"my-service","host":"local-hostname","http_version":"1.1","user_agent":"Go-http-client/1.1","url":"/","user":"current user","time":"2001-02-03T04:05:06Z","message":"Something happened"}
// Output: {"level":"info","role":"my-service","host":"local-hostname","http_version":"1.1","user_agent":"Go-http-client/1.1","url":"/","user":"current user","status":200,"time":"2001-02-03T04:05:06Z","message":"Something happened"}
}

0 comments on commit af1c602

Please sign in to comment.