Documentation
¶
Overview ¶
Package log provides structured logging with multiple sink support.
Index ¶
- func Debug(msg string, attrs ...slog.Attr)
- func Debugf(format string, args ...any)
- func Error(msg string, attrs ...slog.Attr)
- func Errorf(format string, args ...any)
- func Fatal(msg string, attrs ...slog.Attr)
- func Fatalf(format string, args ...any)
- func Info(msg string, attrs ...slog.Attr)
- func Infof(format string, args ...any)
- func SetGlobalLogger(logger Logger)
- func Warn(msg string, attrs ...slog.Attr)
- func Warnf(format string, args ...any)
- type ConsoleSink
- type ConsoleSinkConfig
- type DefaultLogger
- func (l *DefaultLogger) Debug(msg string, attrs ...slog.Attr)
- func (l *DefaultLogger) Debugf(format string, args ...any)
- func (l *DefaultLogger) Error(msg string, attrs ...slog.Attr)
- func (l *DefaultLogger) Errorf(format string, args ...any)
- func (l *DefaultLogger) Fatal(msg string, attrs ...slog.Attr)
- func (l *DefaultLogger) Fatalf(format string, args ...any)
- func (l *DefaultLogger) Info(msg string, attrs ...slog.Attr)
- func (l *DefaultLogger) Infof(format string, args ...any)
- func (l *DefaultLogger) Warn(msg string, attrs ...slog.Attr)
- func (l *DefaultLogger) Warnf(format string, args ...any)
- 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 SetGlobalLogger ¶
func SetGlobalLogger(logger Logger)
SetGlobalLogger sets the global logger instance.
Types ¶
type ConsoleSink ¶
type ConsoleSink struct {
// contains filtered or unexported fields
}
ConsoleSink outputs logs to console with formatting options.
func NewConsoleSink ¶
func NewConsoleSink(cfg ConsoleSinkConfig) *ConsoleSink
NewConsoleSink creates a console sink.
func (*ConsoleSink) Close ¶
func (c *ConsoleSink) Close() error
type ConsoleSinkConfig ¶
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 configuration for console output.
type DefaultLogger ¶
type DefaultLogger struct {
// contains filtered or unexported fields
}
DefaultLogger is the default logger implementation.
func NewDefaultLogger ¶
func NewDefaultLogger(sink Sink, level slog.Level) *DefaultLogger
NewDefaultLogger creates a logger with the given sink and level.
func (*DefaultLogger) Debugf ¶
func (l *DefaultLogger) Debugf(format string, args ...any)
func (*DefaultLogger) Errorf ¶
func (l *DefaultLogger) Errorf(format string, args ...any)
func (*DefaultLogger) Fatalf ¶
func (l *DefaultLogger) Fatalf(format string, args ...any)
func (*DefaultLogger) Infof ¶
func (l *DefaultLogger) Infof(format string, args ...any)
func (*DefaultLogger) Warnf ¶
func (l *DefaultLogger) Warnf(format string, args ...any)
func (*DefaultLogger) WithGroup ¶
func (l *DefaultLogger) WithGroup(name string) Logger
type ElasticsearchSink ¶
type ElasticsearchSink struct {
// contains filtered or unexported fields
}
ElasticsearchSink outputs logs to Elasticsearch.
func NewElasticsearchSink ¶
func NewElasticsearchSink(cfg ElasticsearchSinkConfig) *ElasticsearchSink
NewElasticsearchSink creates an Elasticsearch sink.
func (*ElasticsearchSink) Close ¶
func (e *ElasticsearchSink) Close() error
type ElasticsearchSinkConfig ¶
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 configuration for Elasticsearch output.
type FileSink ¶
type FileSink struct {
// contains filtered or unexported fields
}
FileSink outputs logs to a file with rotation support.
type FileSinkConfig ¶
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"` // not implemented in simple version
MaxAge int `json:"max_age" yaml:"max_age" toml:"max_age"` // not implemented in simple version
Compress bool `json:"compress" yaml:"compress" toml:"compress"` // not implemented in simple version
Format string `json:"format" yaml:"format" toml:"format"` // json, text
}
FileSinkConfig configuration for file output.
type LogConfig ¶
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 extended configuration for logging.
type Logger ¶
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 ...any)
Infof(format string, args ...any)
Warnf(format string, args ...any)
Errorf(format string, args ...any)
Fatalf(format string, args ...any)
With(attrs ...slog.Attr) Logger
WithGroup(name string) Logger
}
Logger is the unified logging interface.
func GetGlobalLogger ¶
func GetGlobalLogger() Logger
GetGlobalLogger returns the global logger instance.
func NewFromLogConfig ¶
NewFromLogConfig creates a logger from extended config with multiple sinks.
type LokiSink ¶
type LokiSink struct {
// contains filtered or unexported fields
}
LokiSink outputs logs to Grafana Loki.
type LokiSinkConfig ¶
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 configuration for Loki output.
type MultiSink ¶
type MultiSink struct {
// contains filtered or unexported fields
}
MultiSink writes to multiple sinks.
func NewMultiSink ¶
NewMultiSink creates a sink that writes to multiple targets.
type Sink ¶
type Sink interface {
Write(ctx context.Context, level slog.Level, msg string, attrs []slog.Attr) error
Close() error
}
Sink is the log output target abstraction.
type SinkHandler ¶
type SinkHandler struct {
// contains filtered or unexported fields
}
SinkHandler implements slog.Handler.