Documentation
¶
Index ¶
- Constants
- func CleanupExpiredLogs(root string, days int) error
- func Close() error
- func CurrentFileName() string
- func Debug(args ...interface{})
- func Debugf(format string, args ...interface{})
- func Debugln(args ...interface{})
- func Error(args ...interface{})
- func Errorf(format string, args ...interface{})
- func Errorln(args ...interface{})
- func Fatal(args ...interface{})
- func Fatalf(format string, args ...interface{})
- func Fatalln(args ...interface{})
- func GetLogger() (*logrus.Logger, error)
- func GetLoggerUnsafe() *logrus.Logger
- func Info(args ...interface{})
- func Infof(format string, args ...interface{})
- func Infoln(args ...interface{})
- func LogLinkFileFPath() string
- func NewLogHelper(settings *Settings) *logrus.Logger
- func NewLogHelperWithError(settings *Settings) (*logrus.Logger, error)
- func Panic(args ...interface{})
- func Panicf(format string, args ...interface{})
- func Panicln(args ...interface{})
- func Print(args ...interface{})
- func Printf(format string, args ...interface{})
- func Println(args ...interface{})
- func SetCustomFormatter(formatter logrus.Formatter)
- func SetLoggerFromYAML(path string) error
- func SetLoggerName(name string)
- func SetLoggerSettings(inSettings ...*Settings)
- func SetLoggerSettingsWithError(inSettings ...*Settings) error
- func Warn(args ...interface{})
- func Warnf(format string, args ...interface{})
- func Warning(args ...interface{})
- func Warningf(format string, args ...interface{})
- func Warningln(args ...interface{})
- func Warnln(args ...interface{})
- func WithField(key string, value interface{}) *logrus.Entry
- func WithFields(fields map[string]interface{}) *logrus.Entry
- type FormatterFactory
- type Settings
- type WithFieldFormatter
- type YamlConfig
Constants ¶
View Source
const ( NameDef = "logger" // 格式器类型常量 FormatterTypeWithField = "withField" FormatterTypeEasy = "easy" FormatterTypeJSON = "json" FormatterTypeText = "text" )
Variables ¶
This section is empty.
Functions ¶
func CleanupExpiredLogs ¶ added in v0.0.14
func GetLoggerUnsafe ¶ added in v0.0.16
GetLoggerUnsafe 保持向后兼容的包装函数,忽略错误
func LogLinkFileFPath ¶ added in v0.0.6
func LogLinkFileFPath() string
LogLinkFileFPath returns the path of the current log file.
func NewLogHelper ¶
func NewLogHelperWithError ¶ added in v0.0.16
NewLogHelperWithError 创建日志助手,返回错误
func SetCustomFormatter ¶ added in v0.0.15
SetCustomFormatter 设置用户自定义格式器
func SetLoggerFromYAML ¶ added in v0.0.14
func SetLoggerSettings ¶ added in v0.0.11
func SetLoggerSettings(inSettings ...*Settings)
func SetLoggerSettingsWithError ¶ added in v0.0.16
SetLoggerSettingsWithError 设置日志配置,返回错误
func WithFields ¶ added in v0.0.15
WithFields 返回一个带有多个字段的 logrus.Entry
Types ¶
type FormatterFactory ¶ added in v0.0.15
type FormatterFactory struct{}
FormatterFactory 格式器工厂
func (*FormatterFactory) CreateFormatter ¶ added in v0.0.15
func (f *FormatterFactory) CreateFormatter(settings *Settings) logrus.Formatter
CreateFormatter 根据设置创建相应的格式器
type Settings ¶ added in v0.0.11
type Settings struct {
OnlyMsg bool // 废弃:仅输出消息,不包含时间戳等额外信息(向后兼容,内部映射到 FormatterType)
Level logrus.Level // 日志级别
LogRootFPath string // 日志根目录
LogNameBase string // 日志名称
RotationTime time.Duration // 日志轮转时间
MaxAge time.Duration // 日志最大保存时间
MaxAgeDays int
MaxSizeMB int
UseHierarchicalPath bool // 是否使用分层路径(YYYY/MM/DD)
// 新增的格式器配置字段
FormatterType string // 格式器类型:"withField", "easy", "json", "text"
TimestampFormat string // 时间戳格式(默认 "2006-01-02 15:04:05.000")
CustomFormatter logrus.Formatter // 用户自定义格式器
DisableTimestamp bool // 是否禁用时间戳
DisableLevel bool // 是否禁用日志级别
DisableCaller bool // 是否禁用调用者信息
FullTimestamp bool // 是否显示完整时间戳
LogFormat string // 自定义日志格式(用于 easy-formatter)
}
func LoadSettingsFromYAML ¶ added in v0.0.14
type WithFieldFormatter ¶ added in v0.0.15
type WithFieldFormatter struct {
TimestampFormat string // 时间戳格式
DisableTimestamp bool // 是否禁用时间戳
DisableLevel bool // 是否禁用日志级别
DisableCaller bool // 是否禁用调用者信息
}
WithFieldFormatter 自定义日志格式器,支持结构化字段输出 输出格式:2025-12-18 18:32:07.379 - [INFO]: 【实时通知】事件广播成功 operation=(a+b)-c result=123.45
type YamlConfig ¶ added in v0.0.14
type YamlConfig struct {
LogRoot string `yaml:"log_root"`
LogNameBase string `yaml:"log_name_base"`
Level string `yaml:"level"`
DaysToKeep int `yaml:"days_to_keep"`
MaxSizeMB int `yaml:"max_size_mb"`
UseHierarchicalPath bool `yaml:"use_hierarchical_path"`
// 新增的格式器配置字段
FormatterType string `yaml:"formatter_type"`
TimestampFormat string `yaml:"timestamp_format"`
DisableTimestamp bool `yaml:"disable_timestamp"`
DisableLevel bool `yaml:"disable_level"`
DisableCaller bool `yaml:"disable_caller"`
FullTimestamp bool `yaml:"full_timestamp"`
LogFormat string `yaml:"log_format"`
}
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
concurrent_demo
command
|
|
|
demo
command
|
|
|
formatter_demo
command
|
|
|
gui_demo
command
|
|
|
rotation_demo
command
|
Click to show internal directories.
Click to hide internal directories.