Skip to content
Snippets Groups Projects
Commit f526180b authored by Semyon Krestyaninov's avatar Semyon Krestyaninov
Browse files

Merge branch 'feature/PRXS-951-1964-ZapCustomFields' into feature/PRXS-951-1961-ZapIntergration

parents 0a5955ba 8217ecad
No related branches found
No related tags found
No related merge requests found
package zap package zap
import ( import (
"context"
"fmt" "fmt"
"go.uber.org/zap" "go.uber.org/zap"
...@@ -41,12 +40,7 @@ func Object(v any) zapcore.Field { ...@@ -41,12 +40,7 @@ func Object(v any) zapcore.Field {
return zap.String("object", object) return zap.String("object", object)
} }
type callerKey struct{} func Caller(v any) zapcore.Field {
// ContextWithCaller добавляет в контекст передаваемый аргумент в качестве "вызывающего" в формате GlobalID.
// Поддерживает один из типов: string, fmt.Stringer. Если передан аргумент другого типа, в качестве вызывающего
// будет установлен "unknown".
func ContextWithCaller(parent context.Context, v any) context.Context {
var caller string var caller string
switch value := v.(type) { switch value := v.(type) {
case string: case string:
...@@ -56,14 +50,6 @@ func ContextWithCaller(parent context.Context, v any) context.Context { ...@@ -56,14 +50,6 @@ func ContextWithCaller(parent context.Context, v any) context.Context {
default: default:
caller = unknownCaller caller = unknownCaller
} }
return context.WithValue(parent, callerKey{}, caller)
}
func CallerFromContext(ctx context.Context) zapcore.Field {
caller, ok := ctx.Value(callerKey{}).(string)
if !ok {
caller = unknownCaller
}
return zap.String("caller", caller) return zap.String("caller", caller)
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment