From dc0f4ed9b883e3708ff7541105f0ff8ae5550b03 Mon Sep 17 00:00:00 2001 From: miya Date: Thu, 6 May 2021 07:51:38 -0500 Subject: [PATCH] mw/logging:enhance req.(fmt.Stringer) (#898) --- middleware/logging/logging.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/middleware/logging/logging.go b/middleware/logging/logging.go index bbeee50e0..0224e8a28 100644 --- a/middleware/logging/logging.go +++ b/middleware/logging/logging.go @@ -27,17 +27,20 @@ func Server(l log.Logger) middleware.Middleware { traceID string ) traceID = trace.SpanContextFromContext(ctx).TraceID().String() + if stringer, ok := req.(fmt.Stringer); ok { + args = stringer.String() + } else { + args = fmt.Sprintf("%+v", req) + } if info, ok := http.FromServerContext(ctx); ok { component = "HTTP" path = info.Request.URL.Path method = info.Request.Method - args = req.(fmt.Stringer).String() query = info.Request.URL.RawQuery } else if info, ok := grpc.FromServerContext(ctx); ok { component = "gRPC" path = info.FullMethod method = "POST" - args = req.(fmt.Stringer).String() } reply, err := handler(ctx, req) if component == "HTTP" {