Skip to content

Commit 8fc505e

Browse files
author
Raphaël Simon
authored
Log request HTTP headers in LogRequest middleware (goadesign#910)
When `verbose` is true
1 parent b0fd166 commit 8fc505e

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

middleware/log_request.go

+10
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ func LogRequest(verbose bool) goa.Middleware {
3232
goa.LogInfo(ctx, "started", r.Method, r.URL.String(), "from", from(req),
3333
"ctrl", goa.ContextController(ctx), "action", goa.ContextAction(ctx))
3434
if verbose {
35+
if len(r.Header) > 0 {
36+
logCtx := make([]interface{}, 2*len(r.Header))
37+
i := 0
38+
for k, v := range r.Header {
39+
logCtx[i] = k
40+
logCtx[i+1] = interface{}(strings.Join(v, ", "))
41+
i = i + 2
42+
}
43+
goa.LogInfo(ctx, "headers", logCtx...)
44+
}
3545
if len(r.Params) > 0 {
3646
logCtx := make([]interface{}, 2*len(r.Params))
3747
i := 0

0 commit comments

Comments
 (0)