btzap

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2025 License: MIT Imports: 8 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// 是否启用控制台日志输出
	EnableConsole bool
	// 是否启用文件日志输出
	EnableFile bool
	// 是否启用Loki输出
	EnableLoki bool
	// 控制台输出的最小日志级别
	ConsoleLevel zapcore.Level
	// 文件输出的最小日志级别
	FileLevel zapcore.Level
	// loki输出的最小日志级别
	LokiLevel zapcore.Level
	// 是否记录调用方信息
	EnableCaller bool
	// 日志文件路径
	FilePath string
	// 日志文件最大大小(MB)
	MaxSize int
	// 保留旧文件的最大个数
	MaxBackups int
	// 保留旧文件的最大天数
	MaxAge int
	// 是否压缩旧文件
	Compress bool
	// Loki配置
	LokiConfig LokiConfig
}

Config 定义了日志配置

type Logger

type Logger struct {
	*zap.Logger
	// contains filtered or unexported fields
}

func NewLogger

func NewLogger(cfg *Config) (*Logger, error)

NewLogger 创建并返回一个新的日志实例

func (*Logger) Close

func (l *Logger) Close() error

Close 关闭日志器

func (*Logger) DPanic

func (l *Logger) DPanic(msg string, fields ...zap.Field)

func (*Logger) Debug

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

重写日志方法以支持同时写入Loki

func (*Logger) Error

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

func (*Logger) Fatal

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

func (*Logger) Info

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

func (*Logger) Panic

func (l *Logger) Panic(msg string, fields ...zap.Field)

func (*Logger) Warn

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

type LokiConfig

type LokiConfig struct {
	// Loki服务器地址
	URL string
	// 批量发送大小
	BatchSize int
	// 日志标签
	Labels map[string]string
	// 发送超时时间(秒)
	Timeout int
	// HTTPClient 是用于发送请求的 HTTP 客户端
	// 如果为 nil,将使用 http.DefaultClient
	HTTPClient *http.Client
}

LokiConfig 定义了Loki相关配置

Jump to

Keyboard shortcuts

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