Documentation
¶
Index ¶
- Variables
- func CleanupLogFile(filepath string) error
- func CleanupLogFiles() error
- func Debug(msg string, fields ...interface{})
- func Debugf(format string, args ...interface{})
- func EnsureLogDir() error
- func EnsureLogDirForPath(logPath string) error
- func Error(msg string, fields ...interface{})
- func Errorf(format string, args ...interface{})
- func Fatal(msg string, fields ...interface{})
- func Fatalf(format string, args ...interface{})
- func GetDefaultLogDir() string
- func GetDefaultLogFile() string
- func GetDefaultLogPath() string
- func Info(msg string, fields ...interface{})
- func Infof(format string, args ...interface{})
- func Init(opts Options)
- func InitWithLogger(logger *Logger)
- func IsEnabled(level Level) bool
- func Panic(msg string, fields ...interface{})
- func Panicf(format string, args ...interface{})
- func SetContextExtractor(extractor ContextExtractor)
- func SetDefaultLogDir(dir string)
- func SetDefaultLogFile(filepath string)
- func SetDefaultLogger(logger *Logger)
- func SetLevel(level Level)
- func SetupDevelopment()
- func SetupProduction()
- func SetupWithOptions(opts Options)
- func Sync() error
- func Warn(msg string, fields ...interface{})
- func Warnf(format string, args ...interface{})
- type ContextExtractor
- type ContextKey
- type DefaultContextExtractor
- type Format
- type Hook
- type Level
- type Logger
- func FromContext(ctx context.Context) *Logger
- func GetDefaultLogger() *Logger
- func Named(name string) *Logger
- func New() *Logger
- func NewDevelopment() *Logger
- func NewNop() *Logger
- func NewProduction() *Logger
- func NewWithOptions(opts Options) *Logger
- func With(fields ...interface{}) *Logger
- func WithContext(ctx context.Context) *Logger
- func WithError(err error) *Logger
- func WithFields(fields map[string]interface{}) *Logger
- func (l *Logger) AddHook(hook Hook)
- func (l *Logger) Clone() *Logger
- func (l *Logger) Debug(msg string, fields ...interface{})
- func (l *Logger) Debugf(format string, args ...interface{})
- func (l *Logger) Error(msg string, fields ...interface{})
- func (l *Logger) Errorf(format string, args ...interface{})
- func (l *Logger) Fatal(msg string, fields ...interface{})
- func (l *Logger) Fatalf(format string, args ...interface{})
- func (l *Logger) GetLevel() Level
- func (l *Logger) GetSugar() *zap.SugaredLogger
- func (l *Logger) GetZap() *zap.Logger
- func (l *Logger) Info(msg string, fields ...interface{})
- func (l *Logger) Infof(format string, args ...interface{})
- func (l *Logger) IsEnabled(level Level) bool
- func (l *Logger) Named(name string) *Logger
- func (l *Logger) Panic(msg string, fields ...interface{})
- func (l *Logger) Panicf(format string, args ...interface{})
- func (l *Logger) RemoveHooks()
- func (l *Logger) SetLevel(level Level)
- func (l *Logger) Sync() error
- func (l *Logger) Warn(msg string, fields ...interface{})
- func (l *Logger) Warnf(format string, args ...interface{})
- func (l *Logger) With(fields ...interface{}) *Logger
- func (l *Logger) WithContext(ctx context.Context) *Logger
- func (l *Logger) WithError(err error) *Logger
- func (l *Logger) WithFields(fields map[string]interface{}) *Logger
- type Options
- type RotateConfig
- type SamplingConfig
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // DefaultLogFile 默认日志文件路径 DefaultLogFile = "app.log" // DefaultLogDir 默认日志目录 DefaultLogDir = "logs" )
默认日志文件路径配置
Functions ¶
func EnsureLogDirForPath ¶
EnsureLogDirForPath 确保指定路径的日志目录存在
func SetContextExtractor ¶
func SetContextExtractor(extractor ContextExtractor)
SetContextExtractor 设置全局上下文提取器
func SetDefaultLogger ¶
func SetDefaultLogger(logger *Logger)
func SetupProduction ¶
func SetupProduction()
func SetupWithOptions ¶
func SetupWithOptions(opts Options)
Types ¶
type ContextExtractor ¶
ContextExtractor 上下文信息提取器
func GetContextExtractor ¶
func GetContextExtractor() ContextExtractor
GetContextExtractor 获取全局上下文提取器
type DefaultContextExtractor ¶
type DefaultContextExtractor struct{}
DefaultContextExtractor 默认上下文提取器
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger 日志管理器
func FromContext ¶
FromContext 从 context.Context 创建带有上下文字段的 logger 自动提取 trace_id 和 request_id 等字段
func GetDefaultLogger ¶
func GetDefaultLogger() *Logger
func WithFields ¶
func (*Logger) WithContext ¶
WithContext 创建带上下文的日志记录器
func (*Logger) WithFields ¶
WithFields 创建带字段的日志记录器
type Options ¶
type Options struct {
Level Level // 日志级别
Format Format // 输出格式 (FormatJSON, FormatConsole, FormatText)
TimeFormat string // 时间格式
Caller bool // 是否显示调用者信息
Stacktrace bool // 是否显示堆栈跟踪
EnableFileOutput bool // 是否启用文件输出
Sampling *SamplingConfig // 采样配置
Rotate *RotateConfig // 日志轮转配置
Fields map[string]interface{} // 默认字段
Hooks []Hook // 钩子函数
}
Options 日志选项
Click to show internal directories.
Click to hide internal directories.