logx

package
v0.0.0-...-45a4d88 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 24, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitContext

func InitContext(ctx context.Context, traceID string) context.Context

func NewTraceID

func NewTraceID() string

func Register

func Register(l Logger)

Register 注册全局日志, 无锁, 请只在初始化时调用

func WithValue

func WithValue(ctx context.Context, field string, value interface{})

Types

type ContextHook

type ContextHook struct{}

func NewContextHook

func NewContextHook() *ContextHook

func (*ContextHook) Fire

func (hook *ContextHook) Fire(entry *logrus.Entry) error

Fire 会在日志输出之前调用,向日志条目中添加从 context 中提取的键值对

func (*ContextHook) Levels

func (hook *ContextHook) Levels() []logrus.Level

Levels 定义 Hook 适用的日志级别

type Field

type Field struct {
	Key   string
	Value any
}

func Any

func Any(key string, value any) Field

func Duration

func Duration(value time.Duration) Field

func Error

func Error(err error) Field

func Int32

func Int32(key string, value int32) Field

func Int64

func Int64(key string, value int64) Field

func String

func String(key, value string) Field

func Time

func Time(key string, value time.Time) Field

type Logger

type Logger interface {
	Debug(msg string, fields ...Field)
	Info(msg string, fields ...Field)
	Warn(msg string, fields ...Field)
	Error(msg string, fields ...Field)
	Fatal(msg string, fields ...Field)
	// WithCtx returns a new Logger with the given context.
	// highly recommended
	WithCtx(ctx context.Context) Logger
	WithField(field ...Field) Logger
	WithSkip(skip int) Logger
}

func L

func L() Logger

func NewLogrusLogger

func NewLogrusLogger() Logger

func NewZapLogger

func NewZapLogger(l *zap.Logger) Logger

type NopLogger

type NopLogger struct{}

func NewNopLogger

func NewNopLogger() *NopLogger

func (*NopLogger) Debug

func (l *NopLogger) Debug(msg string, fields ...Field)

func (*NopLogger) Error

func (l *NopLogger) Error(msg string, fields ...Field)

func (*NopLogger) Fatal

func (l *NopLogger) Fatal(msg string, fields ...Field)

func (*NopLogger) Info

func (l *NopLogger) Info(msg string, fields ...Field)

func (*NopLogger) Warn

func (l *NopLogger) Warn(msg string, fields ...Field)

func (*NopLogger) WithCtx

func (l *NopLogger) WithCtx(ctx context.Context) Logger

func (*NopLogger) WithField

func (l *NopLogger) WithField(field ...Field) Logger

func (*NopLogger) WithSkip

func (l *NopLogger) WithSkip(skip int) Logger

type ZapLogger

type ZapLogger struct {
	// contains filtered or unexported fields
}

func (*ZapLogger) Debug

func (z *ZapLogger) Debug(msg string, fields ...Field)

func (*ZapLogger) Error

func (z *ZapLogger) Error(msg string, fields ...Field)

func (*ZapLogger) Fatal

func (z *ZapLogger) Fatal(msg string, fields ...Field)

func (*ZapLogger) Info

func (z *ZapLogger) Info(msg string, fields ...Field)

func (*ZapLogger) Warn

func (z *ZapLogger) Warn(msg string, fields ...Field)

func (*ZapLogger) WithCtx

func (z *ZapLogger) WithCtx(ctx context.Context) Logger

func (*ZapLogger) WithField

func (z *ZapLogger) WithField(field ...Field) Logger

func (*ZapLogger) WithSkip

func (z *ZapLogger) WithSkip(skip int) Logger

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL