Documentation
¶
Index ¶
- func AddKV(ctx context.Context, kvs ...any) context.Context
- func Debug(ctx context.Context, args ...interface{})
- func DebugKV(ctx context.Context, message string, kvs ...interface{})
- func Debugf(ctx context.Context, format string, args ...interface{})
- func Error(ctx context.Context, args ...interface{})
- func ErrorKV(ctx context.Context, message string, kvs ...interface{})
- func Errorf(ctx context.Context, format string, args ...interface{})
- func Fatal(ctx context.Context, args ...interface{})
- func FatalKV(ctx context.Context, message string, kvs ...interface{})
- func Fatalf(ctx context.Context, format string, args ...interface{})
- func FromContext(ctx context.Context) *zap.SugaredLogger
- func Info(ctx context.Context, args ...interface{})
- func InfoKV(ctx context.Context, message string, kvs ...interface{})
- func Infof(ctx context.Context, format string, args ...interface{})
- func Level() zapcore.Level
- func LevelFromContext(ctx context.Context) zapcore.Level
- func Logger() *zap.SugaredLogger
- func New(level zapcore.Level, options ...zap.Option) *zap.SugaredLogger
- func NewWithSink(level zapcore.LevelEnabler, sink io.Writer, options ...zap.Option) *zap.SugaredLogger
- func Panic(ctx context.Context, args ...interface{})
- func PanicKV(ctx context.Context, message string, kvs ...interface{})
- func Panicf(ctx context.Context, format string, args ...interface{})
- func SetLevel(l zapcore.Level)
- func SetLogger(l *zap.SugaredLogger)
- func ToContext(ctx context.Context, l *zap.SugaredLogger) context.Context
- func Warn(ctx context.Context, args ...interface{})
- func WarnKV(ctx context.Context, message string, kvs ...interface{})
- func Warnf(ctx context.Context, format string, args ...interface{})
- func WithFields(ctx context.Context, fields ...zap.Field) context.Context
- func WithKV(ctx context.Context, key string, value any) context.Context
- func WithLevel(lvl zapcore.Level) zap.Option
- func WithName(ctx context.Context, name string) context.Context
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddKV ¶
AddKV Adds KV pairs to
Example ¶
ctx := AddKV(
context.Background(),
zap.String("a", "b"),
zap.Int("c", 1),
zap.Error(assert.AnError),
)
// В сообщении появятся поля, переданные в AddKV.
Info(ctx, "some message")
func FromContext ¶
func FromContext(ctx context.Context) *zap.SugaredLogger
FromContext Gets the logger from contet
func LevelFromContext ¶
LevelFromContext Gets the log_level from the context logger
func NewWithSink ¶
func NewWithSink(level zapcore.LevelEnabler, sink io.Writer, options ...zap.Option) *zap.SugaredLogger
func ToContext ¶
ToContext Attaches a logger to context
Example ¶
logger := Logger()
customLogger := logger.With(
zap.String("component", "database"),
)
ctx := ToContext(context.Background(), customLogger)
loggerFromContext := FromContext(ctx)
// Будет содержать дополнительное поле component.
loggerFromContext.Info("some message")
func WithFields ¶
WithFields Adds fields to logger from context
Example ¶
// context, containing logger
ctx := context.Background()
// new context with logger fields
ctx = WithFields(ctx,
zap.String("kafka-topic", "my topic"),
zap.Int32("kafka-partition", 1),
)
_ = ctx
func WithKV ¶
WithKV Adds KV pair to logger from context
Example ¶
// context, containing logger ctx := context.Background() // new context with logger fields ctx = WithKV(ctx, "my key", "my value") _ = ctx
func WithLevel ¶
WithLevel option that allows you to create a logger with a specified level from an existing one
Example ¶
Logger().Desugar().WithOptions(WithLevel(zapcore.DebugLevel)).Sugar()
func WithName ¶
WithName Set a name for the logger
Example ¶
// context, containing logger ctx := context.Background() ctx = WithName(ctx, "GetApples") // -> "GetApples" ctx = WithName(ctx, "AppleManager") // - > "GetApples.AppleManager" ctx = WithName(ctx, "DB") // -> "GetApples.AppleManager.DB" _ = ctx
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.