Documentation
¶
Index ¶
- func Debug(msg string, attrs ...slog.Attr)
- func Debugf(format string, args ...interface{})
- func Error(msg string, attrs ...slog.Attr)
- func ErrorCompat(err error, args ...slog.Attr)
- func Errorf(format string, args ...interface{})
- func Fatal(msg string, attrs ...slog.Attr)
- func Fatalf(format string, args ...interface{})
- func Info(msg string, attrs ...slog.Attr)
- func InfoCompat(format string, args ...slog.Attr)
- func Infof(format string, args ...interface{})
- func SetGlobalLogger(logger Logger)
- func Warn(msg string, attrs ...slog.Attr)
- func Warnf(format string, args ...interface{})
- type ConsoleSink
- type ConsoleSinkConfig
- type DefaultLogger
- func (l *DefaultLogger) Debug(msg string, attrs ...slog.Attr)
- func (l *DefaultLogger) Debugf(format string, args ...interface{})
- func (l *DefaultLogger) Error(msg string, attrs ...slog.Attr)
- func (l *DefaultLogger) Errorf(format string, args ...interface{})
- func (l *DefaultLogger) Fatal(msg string, attrs ...slog.Attr)
- func (l *DefaultLogger) Fatalf(format string, args ...interface{})
- func (l *DefaultLogger) Info(msg string, attrs ...slog.Attr)
- func (l *DefaultLogger) Infof(format string, args ...interface{})
- func (l *DefaultLogger) Warn(msg string, attrs ...slog.Attr)
- func (l *DefaultLogger) Warnf(format string, args ...interface{})
- func (l *DefaultLogger) With(attrs ...slog.Attr) Logger
- func (l *DefaultLogger) WithGroup(name string) Logger
- type ElasticsearchSink
- type ElasticsearchSinkConfig
- type FileSink
- type FileSinkConfig
- type LogConfig
- type Logger
- type LokiSink
- type LokiSinkConfig
- type MultiSink
- type Sink
- type SinkHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InfoCompat ¶ added in v1.0.2
InfoCompat 兼容旧接口
func SetGlobalLogger ¶ added in v1.0.2
func SetGlobalLogger(logger Logger)
SetGlobalLogger 设置全局日志记录器
Types ¶
type ConsoleSink ¶ added in v1.0.2
type ConsoleSink struct {
// contains filtered or unexported fields
}
ConsoleSink 控制台输出
func NewConsoleSink ¶ added in v1.0.2
func NewConsoleSink(cfg ConsoleSinkConfig) *ConsoleSink
func (*ConsoleSink) Close ¶ added in v1.0.2
func (c *ConsoleSink) Close() error
type ConsoleSinkConfig ¶ added in v1.0.2
type ConsoleSinkConfig struct {
Format string `json:"format" yaml:"format" toml:"format"` // json, text, color
Output string `json:"output" yaml:"output" toml:"output"` // stdout, stderr
}
ConsoleSinkConfig 控制台输出配置
type DefaultLogger ¶ added in v1.0.2
type DefaultLogger struct {
// contains filtered or unexported fields
}
DefaultLogger 默认日志记录器实现
func NewDefaultLogger ¶ added in v1.0.2
func NewDefaultLogger(sink Sink, level slog.Level) *DefaultLogger
func (*DefaultLogger) Debug ¶ added in v1.0.2
func (l *DefaultLogger) Debug(msg string, attrs ...slog.Attr)
func (*DefaultLogger) Debugf ¶ added in v1.0.2
func (l *DefaultLogger) Debugf(format string, args ...interface{})
func (*DefaultLogger) Error ¶ added in v1.0.2
func (l *DefaultLogger) Error(msg string, attrs ...slog.Attr)
func (*DefaultLogger) Errorf ¶ added in v1.0.2
func (l *DefaultLogger) Errorf(format string, args ...interface{})
func (*DefaultLogger) Fatal ¶ added in v1.0.2
func (l *DefaultLogger) Fatal(msg string, attrs ...slog.Attr)
func (*DefaultLogger) Fatalf ¶ added in v1.0.2
func (l *DefaultLogger) Fatalf(format string, args ...interface{})
func (*DefaultLogger) Info ¶ added in v1.0.2
func (l *DefaultLogger) Info(msg string, attrs ...slog.Attr)
func (*DefaultLogger) Infof ¶ added in v1.0.2
func (l *DefaultLogger) Infof(format string, args ...interface{})
func (*DefaultLogger) Warn ¶ added in v1.0.2
func (l *DefaultLogger) Warn(msg string, attrs ...slog.Attr)
func (*DefaultLogger) Warnf ¶ added in v1.0.2
func (l *DefaultLogger) Warnf(format string, args ...interface{})
func (*DefaultLogger) With ¶ added in v1.0.2
func (l *DefaultLogger) With(attrs ...slog.Attr) Logger
func (*DefaultLogger) WithGroup ¶ added in v1.0.2
func (l *DefaultLogger) WithGroup(name string) Logger
type ElasticsearchSink ¶ added in v1.0.2
type ElasticsearchSink struct {
// contains filtered or unexported fields
}
ElasticsearchSink Elasticsearch输出
func NewElasticsearchSink ¶ added in v1.0.2
func NewElasticsearchSink(cfg ElasticsearchSinkConfig) *ElasticsearchSink
func (*ElasticsearchSink) Close ¶ added in v1.0.2
func (e *ElasticsearchSink) Close() error
type ElasticsearchSinkConfig ¶ added in v1.0.2
type ElasticsearchSinkConfig struct {
URL string `json:"url" yaml:"url" toml:"url"`
Index string `json:"index" yaml:"index" toml:"index"`
Timeout time.Duration `json:"timeout" yaml:"timeout" toml:"timeout"`
}
ElasticsearchSinkConfig Elasticsearch输出配置
type FileSink ¶ added in v1.0.2
type FileSink struct {
// contains filtered or unexported fields
}
FileSink 文件输出
func NewFileSink ¶ added in v1.0.2
func NewFileSink(cfg FileSinkConfig) *FileSink
type FileSinkConfig ¶ added in v1.0.2
type FileSinkConfig struct {
Filename string `json:"filename" yaml:"filename" toml:"filename"`
MaxSize int `json:"max_size" yaml:"max_size" toml:"max_size"` // MB
MaxBackups int `json:"max_backups" yaml:"max_backups" toml:"max_backups"`
MaxAge int `json:"max_age" yaml:"max_age" toml:"max_age"` // days
Compress bool `json:"compress" yaml:"compress" toml:"compress"`
Format string `json:"format" yaml:"format" toml:"format"` // json, text
}
FileSinkConfig 文件输出配置
type LogConfig ¶ added in v1.0.2
type LogConfig struct {
Level string `json:"level" yaml:"level" toml:"level"`
Format string `json:"format" yaml:"format" toml:"format"`
Console ConsoleSinkConfig `json:"console" yaml:"console" toml:"console"`
File FileSinkConfig `json:"file" yaml:"file" toml:"file"`
Elasticsearch ElasticsearchSinkConfig `json:"elasticsearch" yaml:"elasticsearch" toml:"elasticsearch"`
Loki LokiSinkConfig `json:"loki" yaml:"loki" toml:"loki"`
}
LogConfig 日志配置
type Logger ¶ added in v1.0.2
type Logger interface {
Debug(msg string, attrs ...slog.Attr)
Info(msg string, attrs ...slog.Attr)
Warn(msg string, attrs ...slog.Attr)
Error(msg string, attrs ...slog.Attr)
Fatal(msg string, attrs ...slog.Attr)
Debugf(format string, args ...interface{})
Infof(format string, args ...interface{})
Warnf(format string, args ...interface{})
Errorf(format string, args ...interface{})
Fatalf(format string, args ...interface{})
With(attrs ...slog.Attr) Logger
WithGroup(name string) Logger
}
Logger 统一的日志记录接口
type LokiSink ¶ added in v1.0.2
type LokiSink struct {
// contains filtered or unexported fields
}
LokiSink Loki输出
func NewLokiSink ¶ added in v1.0.2
func NewLokiSink(cfg LokiSinkConfig) *LokiSink
type LokiSinkConfig ¶ added in v1.0.2
type LokiSinkConfig struct {
URL string `json:"url" yaml:"url" toml:"url"`
Labels map[string]string `json:"labels" yaml:"labels" toml:"labels"`
Timeout time.Duration `json:"timeout" yaml:"timeout" toml:"timeout"`
}
LokiSinkConfig Loki输出配置
type MultiSink ¶ added in v1.0.2
type MultiSink struct {
// contains filtered or unexported fields
}
MultiSink 多输出目标
func NewMultiSink ¶ added in v1.0.2
type Sink ¶ added in v1.0.2
type Sink interface {
Write(ctx context.Context, level slog.Level, msg string, attrs []slog.Attr) error
Close() error
}
Sink 日志输出目标抽象
type SinkHandler ¶ added in v1.0.2
type SinkHandler struct {
// contains filtered or unexported fields
}
SinkHandler slog.Handler 实现
Click to show internal directories.
Click to hide internal directories.