mw/logging:enhance req.(fmt.Stringer) (#898)

pull/900/head
miya 4 years ago committed by GitHub
parent eed0ac7d4a
commit dc0f4ed9b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      middleware/logging/logging.go

@ -27,17 +27,20 @@ func Server(l log.Logger) middleware.Middleware {
traceID string traceID string
) )
traceID = trace.SpanContextFromContext(ctx).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 { if info, ok := http.FromServerContext(ctx); ok {
component = "HTTP" component = "HTTP"
path = info.Request.URL.Path path = info.Request.URL.Path
method = info.Request.Method method = info.Request.Method
args = req.(fmt.Stringer).String()
query = info.Request.URL.RawQuery query = info.Request.URL.RawQuery
} else if info, ok := grpc.FromServerContext(ctx); ok { } else if info, ok := grpc.FromServerContext(ctx); ok {
component = "gRPC" component = "gRPC"
path = info.FullMethod path = info.FullMethod
method = "POST" method = "POST"
args = req.(fmt.Stringer).String()
} }
reply, err := handler(ctx, req) reply, err := handler(ctx, req)
if component == "HTTP" { if component == "HTTP" {

Loading…
Cancel
Save