log

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

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 Debug

func Debug(args ...interface{})

Debug 输出 Debug 级别日志 参数:

  • args: 日志参数 | Log arguments

func DebugWithFields

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

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

func Duration(key string, value time.Duration) zap.Field

Duration 结构化日志时长字段 参数:

  • key: 字段名 | Field name
  • value: 字段值 | Field value

返回值:

  • zap.Field: Zap 字段 | Zap field

func Error

func Error(args ...interface{})

Error 输出 Error 级别日志 参数:

  • args: 日志参数 | Log arguments

func ErrorWithFields

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

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 Fatal

func Fatal(args ...interface{})

Fatal 输出 Fatal 级别日志 参数:

  • args: 日志参数 | Log arguments

func FatalWithFields

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

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 Info

func Info(args ...interface{})

Info 输出 Info 级别日志 参数:

  • args: 日志参数 | Log arguments

func InfoWithFields

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

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

func InitLogger(cfg *Config) error

InitLogger 初始化日志 参数:

  • cfg: 日志配置(nil 则使用默认配置)| Log config (use default if nil)

返回值:

  • error: 初始化失败时返回错误 | Error if initialization failed

func Int

func Int(key string, value int) zap.Field

Int 结构化日志整型字段 参数:

  • key: 字段名 | Field name
  • value: 字段值 | Field value

返回值:

  • zap.Field: Zap 字段 | Zap field

func String

func String(key, value string) zap.Field

String 结构化日志字符串字段 参数:

  • key: 字段名 | Field name
  • value: 字段值 | Field value

返回值:

  • zap.Field: Zap 字段 | Zap field

func Uint64

func Uint64(key string, value uint64) zap.Field

Uint64 结构化日志无符号整型字段 参数:

  • key: 字段名 | Field name
  • value: 字段值 | Field value

返回值:

  • zap.Field: Zap 字段 | Zap field

func Warn

func Warn(args ...interface{})

Warn 输出 Warn 级别日志 参数:

  • args: 日志参数 | Log arguments

func WarnWithFields

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

WarnWithFields 输出带字段的 Warn 级别日志 参数:

  • msg: 日志消息 | Log message
  • fields: 结构化字段 | Structured fields

func Warnf

func Warnf(template string, args ...interface{})

Warnf 输出格式化 Warn 级别日志 参数:

  • template: 格式化模板 | Format template
  • args: 模板参数 | Template arguments

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

Jump to

Keyboard shortcuts

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