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
import (
"context"
"fmt"
"go.uber.org/zap"
......@@ -41,12 +40,7 @@ func Object(v any) zapcore.Field {
return zap.String("object", object)
}
type callerKey struct{}
// ContextWithCaller добавляет в контекст передаваемый аргумент в качестве "вызывающего" в формате GlobalID.
// Поддерживает один из типов: string, fmt.Stringer. Если передан аргумент другого типа, в качестве вызывающего
// будет установлен "unknown".
func ContextWithCaller(parent context.Context, v any) context.Context {
func Caller(v any) zapcore.Field {
var caller string
switch value := v.(type) {
case string:
......@@ -56,14 +50,6 @@ func ContextWithCaller(parent context.Context, v any) context.Context {
default:
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)
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment