logger

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2025 License: BSD-3-Clause Imports: 9 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BatchDebug added in v0.4.0

func BatchDebug(msg string, fields ...zap.Field)

BatchDebug 全局批处理Debug日志

func BatchError added in v0.4.0

func BatchError(msg string, fields ...zap.Field)

BatchError 全局批处理Error日志

func BatchInfo added in v0.4.0

func BatchInfo(msg string, fields ...zap.Field)

BatchInfo 全局批处理Info日志

func BatchWarn added in v0.4.0

func BatchWarn(msg string, fields ...zap.Field)

BatchWarn 全局批处理Warn日志

func Default

func Default() *zap.Logger

Default the default log instance

func EnableBatchLogging added in v0.4.0

func EnableBatchLogging(config BatchConfig)

EnableBatchLogging 启用全局批处理日志

func FlushBatchLogs added in v0.4.0

func FlushBatchLogs()

FlushBatchLogs 刷新全局批处理日志

func SetContextLogger

func SetContextLogger(ctx context.Context, log StdLogger) context.Context

SetContextLogger context with tags logger

Types

type BatchConfig added in v0.4.0

type BatchConfig struct {
	FlushSize     int           // 批量大小,默认100
	FlushInterval time.Duration // 刷新间隔,默认1秒
	BufferSize    int           // 缓冲区大小,默认1000
}

BatchConfig 批处理配置

type BatchLogger added in v0.4.0

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

BatchLogger 批处理日志器

func NewBatchLogger added in v0.4.0

func NewBatchLogger(baseLogger *zap.Logger, config BatchConfig) *BatchLogger

NewBatchLogger 创建批处理日志器

func (*BatchLogger) Close added in v0.4.0

func (bl *BatchLogger) Close() error

Close 关闭批处理日志器

func (*BatchLogger) Debug added in v0.4.0

func (bl *BatchLogger) Debug(msg string, fields ...zap.Field)

Debug 批处理Debug日志

func (*BatchLogger) Error added in v0.4.0

func (bl *BatchLogger) Error(msg string, fields ...zap.Field)

Error 批处理Error日志

func (*BatchLogger) Fatal added in v0.4.0

func (bl *BatchLogger) Fatal(msg string, fields ...zap.Field)

Fatal Fatal日志(立即刷新)

func (*BatchLogger) Flush added in v0.4.0

func (bl *BatchLogger) Flush()

Flush 手动刷新缓冲区

func (*BatchLogger) Info added in v0.4.0

func (bl *BatchLogger) Info(msg string, fields ...zap.Field)

Info 批处理Info日志

func (*BatchLogger) Stats added in v0.4.0

func (bl *BatchLogger) Stats() BatchStats

Stats 获取批处理统计

func (*BatchLogger) Warn added in v0.4.0

func (bl *BatchLogger) Warn(msg string, fields ...zap.Field)

Warn 批处理Warn日志

type BatchStats added in v0.4.0

type BatchStats struct {
	TotalLogs    int64   `json:"total_logs"`
	BatchedLogs  int64   `json:"batched_logs"`
	FlushCount   int64   `json:"flush_count"`
	DroppedLogs  int64   `json:"dropped_logs"`
	AvgBatchSize float64 `json:"avg_batch_size"`
}

BatchStats 批处理统计

type BatchWrapper added in v0.4.0

type BatchWrapper struct {
	*BatchLogger
	// contains filtered or unexported fields
}

WithBatch 包装logger以支持批处理

func NewBatchWrapper added in v0.4.0

func NewBatchWrapper(logger *zap.Logger, config BatchConfig) *BatchWrapper

NewBatchWrapper 创建批处理包装器

func (*BatchWrapper) With added in v0.4.0

func (bw *BatchWrapper) With(fields ...zap.Field) *zap.Logger

With 实现StdLogger接口

type StdLogger

type StdLogger interface {
	// With with any map data, the value of key must be string, int ... basic value
	With(m ...zap.Field) *zap.Logger
	// Debug print the debug log if the len(args) is 0, the args will be ignored
	Debug(msg string, fields ...zap.Field)
	Info(msg string, fields ...zap.Field)
	Warn(msg string, fields ...zap.Field)
	Error(msg string, fields ...zap.Field)
	Fatal(msg string, fields ...zap.Field)
}

StdLogger the standard logger

func Action

func Action(action string) StdLogger

Action set action filed for logger

func GetContextLogger

func GetContextLogger(ctx context.Context) StdLogger

GetContextLogger extract logger from context

func With

func With(m ...zap.Field) StdLogger

With with any map data, the value of key must be string, int ... basic value

func WithContext

func WithContext(ctx context.Context) StdLogger

WithContext - 优化版本,使用对象池

func WithTags

func WithTags(m map[string]string) StdLogger

WithTags with map string string tags - 优化版本

Jump to

Keyboard shortcuts

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