Documentation
¶
Index ¶
- func Debug(msg string, fields ...Field)
- func Error(msg string, fields ...Field)
- func Fatal(msg string, fields ...Field)
- func Info(msg string, fields ...Field)
- func Initialize(config Config) error
- func Sync() error
- func Warn(msg string, fields ...Field)
- type Config
- type Field
- type FileConfig
- type GormLogger
- func (l *GormLogger) Error(ctx context.Context, msg string, data ...interface{})
- func (l *GormLogger) Info(ctx context.Context, msg string, data ...interface{})
- func (l *GormLogger) LogMode(level gormlogger.LogLevel) gormlogger.Interface
- func (l *GormLogger) Trace(ctx context.Context, begin time.Time, ...)
- func (l *GormLogger) Warn(ctx context.Context, msg string, data ...interface{})
- type Level
- type Logger
- type LoggerType
- type OutputType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
Type LoggerType // 日志驱动类型: zap 或 zerolog
Level Level // 日志级别
Output OutputType // 输出类型: stdout, file, both
File FileConfig // 文件输出配置
EnableCaller bool // 是否显示调用者信息
JSONFormat bool // 是否使用 JSON 格式
}
Config 日志配置
type FileConfig ¶
type FileConfig struct {
Filename string // 日志文件路径
MaxSize int // 单个文件最大大小(MB)
MaxBackups int // 保留的旧文件最大数量
MaxAge int // 保留旧文件的最大天数
Compress bool // 是否压缩旧文件
}
FileConfig 文件输出配置
type GormLogger ¶
type GormLogger struct {
LogLevel gormlogger.LogLevel
SlowThreshold time.Duration
IgnoreRecordNotFoundError bool
// contains filtered or unexported fields
}
GormLogger GORM 日志适配器
func (*GormLogger) Error ¶
func (l *GormLogger) Error(ctx context.Context, msg string, data ...interface{})
Error 记录 error 级别日志
func (*GormLogger) Info ¶
func (l *GormLogger) Info(ctx context.Context, msg string, data ...interface{})
Info 记录 info 级别日志
func (*GormLogger) LogMode ¶
func (l *GormLogger) LogMode(level gormlogger.LogLevel) gormlogger.Interface
LogMode 设置日志级别
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)
With(fields ...Field) Logger // 添加字段
Named(name string) Logger // 添加命名空间
Sync() error // 刷新缓冲区
}
Logger 统一日志接口
type LoggerType ¶
type LoggerType string
LoggerType 日志驱动类型
const ( LoggerTypeZap LoggerType = "zap" LoggerTypeZerolog LoggerType = "zerolog" )
type OutputType ¶
type OutputType string
OutputType 输出类型
const ( OutputStdout OutputType = "stdout" OutputFile OutputType = "file" OutputBoth OutputType = "both" )
Click to show internal directories.
Click to hide internal directories.