diff --git a/log/fields_http.go b/log/fields_http.go index 5281003..d251fe9 100644 --- a/log/fields_http.go +++ b/log/fields_http.go @@ -5,6 +5,9 @@ import ( ) const ( + // HTTPServerNameKey represents the name of the service handling the request + HTTPServerNameKey = "http_server_name" + // HTTPMethodKey represents the HTTP request method. HTTPMethodKey = "http_method" @@ -44,6 +47,10 @@ const ( HTTPSessionIDKey = "http_session_id" ) +func FHTTPServerName(id string) zap.Field { + return zap.String(HTTPServerNameKey, id) +} + func FHTTPRequestID(id string) zap.Field { return zap.String(HTTPRequestIDKey, id) } diff --git a/log/with.go b/log/with.go index 17a8d75..d7fb699 100644 --- a/log/with.go +++ b/log/with.go @@ -17,11 +17,15 @@ func WithError(l *zap.Logger, err error) *zap.Logger { return l.With(FError(err)) } +func WithHTTPServerName(l *zap.Logger, name string) *zap.Logger { + return l.With(FHTTPServerName(name)) +} + func WithServiceName(l *zap.Logger, name string) *zap.Logger { return l.With(FServiceName(name)) } -func WithTraceID(l *zap.Logger, ctx context.Context) *zap.Logger { //nolint:revive +func WithTraceID(l *zap.Logger, ctx context.Context) *zap.Logger { if spanCtx := trace.SpanContextFromContext(ctx); spanCtx.IsValid() { l = l.With(FTraceID(spanCtx.TraceID().String())) }