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.LevelEnabler, 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 New ΒΆ
func New(level zapcore.LevelEnabler, options ...zap.Option) *zap.SugaredLogger
New create a new logger with specific log_leve & options
func NewWithSink ΒΆ
func NewWithSink(level zapcore.LevelEnabler, sink io.Writer, options ...zap.Option) *zap.SugaredLogger
func SetLogger ΒΆ
func SetLogger(l *zap.SugaredLogger)
SetLogger Set global logger (not thread safe)
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.