

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 10
click for more info
Not enough gems
Cost: 6 gems
1: Logging Context
incomplete
2: Build Information
incomplete
3: Instance Context
incomplete
4: Request Context
incomplete
5: User Context
incomplete
6: HTTP Error Responses
incomplete
7: Inter-Process Context
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
Now that we can pass logging context upstream, we can improve HTTP error logging. Wouldn't it be useful to include stack traces whenever we log an error status?
We'll start by adding a small helper that wraps http.Error. It still sends the HTTP response, but first stores the error in LogContext (if present) so request logs can include it:
func httpError(ctx context.Context, w http.ResponseWriter, status int, err error) {
if logCtx, ok := ctx.Value(logContextKey).(*LogContext); ok {
logCtx.Error = err
}
http.Error(w, err.Error(), status)
}
Now request logs for error responses include full error details (including stack traces when present). How handy is that?
Capture HTTP response errors in request logs.
Pass lowercase internal messages (for example, unauthorized and internal server error) so logs stay consistent. That's the Go standard.
Restart your server with LINKO_LOG_FILE=linko.access.log set:
LINKO_LOG_FILE=linko.access.log go run .
Run and submit the CLI tests from the root of the Linko repo.