Documentation
¶
Index ¶
- Variables
- func Debug(args ...interface{})
- func DebugWithFields(msg string, fields ...zap.Field)
- func Debugf(template string, args ...interface{})
- func Duration(key string, value time.Duration) zap.Field
- func Error(args ...interface{})
- func ErrorWithFields(msg string, fields ...zap.Field)
- func Errorf(template string, args ...interface{})
- func Fatal(args ...interface{})
- func FatalWithFields(msg string, fields ...zap.Field)
- func Fatalf(template string, args ...interface{})
- func Info(args ...interface{})
- func InfoWithFields(msg string, fields ...zap.Field)
- func Infof(template string, args ...interface{})
- func InitLogger(cfg *Config) error
- func Int(key string, value int) zap.Field
- func String(key, value string) zap.Field
- func Uint64(key string, value uint64) zap.Field
- func Warn(args ...interface{})
- func WarnWithFields(msg string, fields ...zap.Field)
- func Warnf(template string, args ...interface{})
- type Config
Constants ¶
This section is empty.
Variables ¶
View Source
var ( GlobalLogger *zap.Logger // 标准 Zap Logger | Standard Zap Logger SugarLogger *zap.SugaredLogger // 简化版日志(易用性优先)| Simplified logger (ease of use first) )
全局日志实例 | Global log instances
Functions ¶
func DebugWithFields ¶
DebugWithFields 输出带字段的 Debug 级别日志 参数:
- msg: 日志消息 | Log message
- fields: 结构化字段 | Structured fields
func Debugf ¶
func Debugf(template string, args ...interface{})
Debugf 输出格式化 Debug 级别日志 参数:
- template: 格式化模板 | Format template
- args: 模板参数 | Template arguments
func Duration ¶
Duration 结构化日志时长字段 参数:
- key: 字段名 | Field name
- value: 字段值 | Field value
返回值:
- zap.Field: Zap 字段 | Zap field
func ErrorWithFields ¶
ErrorWithFields 输出带字段的 Error 级别日志 参数:
- msg: 日志消息 | Log message
- fields: 结构化字段 | Structured fields
func Errorf ¶
func Errorf(template string, args ...interface{})
Errorf 输出格式化 Error 级别日志 参数:
- template: 格式化模板 | Format template
- args: 模板参数 | Template arguments
func FatalWithFields ¶
FatalWithFields 输出带字段的 Fatal 级别日志 参数:
- msg: 日志消息 | Log message
- fields: 结构化字段 | Structured fields
func Fatalf ¶
func Fatalf(template string, args ...interface{})
Fatalf 输出格式化 Fatal 级别日志 参数:
- template: 格式化模板 | Format template
- args: 模板参数 | Template arguments
func InfoWithFields ¶
InfoWithFields 输出带字段的 Info 级别日志 参数:
- msg: 日志消息 | Log message
- fields: 结构化字段 | Structured fields
func Infof ¶
func Infof(template string, args ...interface{})
Infof 输出格式化 Info 级别日志 参数:
- template: 格式化模板 | Format template
- args: 模板参数 | Template arguments
func InitLogger ¶
InitLogger 初始化日志 参数:
- cfg: 日志配置(nil 则使用默认配置)| Log config (use default if nil)
返回值:
- error: 初始化失败时返回错误 | Error if initialization failed
func Int ¶
Int 结构化日志整型字段 参数:
- key: 字段名 | Field name
- value: 字段值 | Field value
返回值:
- zap.Field: Zap 字段 | Zap field
func String ¶
String 结构化日志字符串字段 参数:
- key: 字段名 | Field name
- value: 字段值 | Field value
返回值:
- zap.Field: Zap 字段 | Zap field
func Uint64 ¶
Uint64 结构化日志无符号整型字段 参数:
- key: 字段名 | Field name
- value: 字段值 | Field value
返回值:
- zap.Field: Zap 字段 | Zap field
func WarnWithFields ¶
WarnWithFields 输出带字段的 Warn 级别日志 参数:
- msg: 日志消息 | Log message
- fields: 结构化字段 | Structured fields
Types ¶
type Config ¶
type Config struct {
Level string // 日志级别 debug/info/warn/error | Log level debug/info/warn/error
Mode string // 运行模式 dev(控制台)/prod(文件) | Run mode dev(console)/prod(file)
FilePath string // 日志文件路径(prod必填) | Log file path (required for prod)
MaxSize int // 单个日志文件大小(MB) | Single log file size (MB)
MaxBackups int // 最大备份数 | Max backup count
MaxAge int // 最大保留天数 | Max retention days
Compress bool // 是否压缩备份 | Whether to compress backups
ShowLine bool // 是否显示代码行号 | Whether to show code line numbers
EncodeJson bool // 是否 JSON 格式输出 | Whether to output in JSON format
TimeFormat string // 时间格式 | Time format
}
Config 日志配置结构体 整合日志级别、输出模式、文件轮转等所有可配置项 Config is the log configuration structure Integrates all configurable items such as log level, output mode, file rotation
Click to show internal directories.
Click to hide internal directories.