Documentation
¶
Overview ¶
Package logger
Package logger提供了功能丰富的日志记录功能。
Package logger 提供了日志文件轮转的功能。
Index ¶
- func Debug(args ...interface{})
- func Debugf(format string, args ...interface{})
- func Error(args ...interface{})
- func Errorf(format string, args ...interface{})
- func Fatal(args ...interface{})
- func Fatalf(format string, args ...interface{})
- func Info(args ...interface{})
- func Infof(format string, args ...interface{})
- func InitGlobalLogger(c LogConfig) (io.Closer, error)
- func SetFormatter(formatter Formatter)
- func SetLevel(level Level)
- func SetOutput(out io.Writer)
- func Warn(args ...interface{})
- func Warnf(format string, args ...interface{})
- type Entry
- type Fields
- type Formatter
- type JSONFormatter
- type Level
- type LogConfig
- type LogRotator
- type Logger
- func (l *Logger) Debug(args ...interface{})
- func (l *Logger) Debugf(format string, args ...interface{})
- func (l *Logger) Error(args ...interface{})
- func (l *Logger) Errorf(format string, args ...interface{})
- func (l *Logger) Fatal(args ...interface{})
- func (l *Logger) Fatalf(format string, args ...interface{})
- func (l *Logger) Info(args ...interface{})
- func (l *Logger) Infof(format string, args ...interface{})
- func (l *Logger) Warn(args ...interface{})
- func (l *Logger) Warnf(format string, args ...interface{})
- func (l *Logger) WithFields(fields Fields) *Entry
- type Option
- type TextFormatter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InitGlobalLogger ¶
InitGlobalLogger 封装了创建和设置全局日志记录器的逻辑 它会配置默认的 logger,使其同时输出到控制台和轮转文件
Types ¶
type Entry ¶
type Entry struct {
Logger *Logger
Time time.Time
Level Level
Message string
Fields Fields
File string
Line int
Func string
// contains filtered or unexported fields
}
Entry 代表一个日志条目
type LogRotator ¶
type LogRotator struct {
// contains filtered or unexported fields
}
LogRotator 实现了 io.WriteCloser 接口,用于按大小和时间轮转日志文件。
func NewRotator ¶
func NewRotator(filename string, maxSize int64, maxBackups int, maxAgeDays int) (*LogRotator, error)
NewRotator 创建一个新的 LogRotator 实例。 filename: 日志文件的路径。 maxSize: 单个文件的最大大小(字节)。 maxBackups: 要保留的旧日志文件的最大数量。 maxAgeDays: 要保留旧日志文件的最大天数。
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger 是日志记录器的核心结构
func (*Logger) WithFields ¶
WithFields 为 Logger 添加结构化字段,返回一个 Entry
Click to show internal directories.
Click to hide internal directories.