Documentation
¶
Index ¶
- type AsyncLogger
- func (a *AsyncLogger) BufferLen() int
- func (a *AsyncLogger) Close() error
- func (a *AsyncLogger) Debug(msg string, keyvals ...slog.Attr)
- func (a *AsyncLogger) DebugContext(ctx context.Context, msg string, keyvals ...slog.Attr)
- func (a *AsyncLogger) Error(msg string, keyvals ...slog.Attr)
- func (a *AsyncLogger) ErrorContext(ctx context.Context, msg string, keyvals ...slog.Attr)
- func (a *AsyncLogger) Fatal(msg string, keyvals ...slog.Attr)
- func (a *AsyncLogger) Flush()
- func (a *AsyncLogger) Info(msg string, keyvals ...slog.Attr)
- func (a *AsyncLogger) InfoContext(ctx context.Context, msg string, keyvals ...slog.Attr)
- func (a *AsyncLogger) IsFull() bool
- func (a *AsyncLogger) Warn(msg string, keyvals ...slog.Attr)
- func (a *AsyncLogger) WarnContext(ctx context.Context, msg string, keyvals ...slog.Attr)
- type AsyncOption
- type ContextExtractor
- type ErrorHandler
- type Hook
- type Level
- type Logger
- func (l *Logger) AddSink(s sink.Sink)
- func (l *Logger) Close() error
- func (l *Logger) Debug(msg string, keyvals ...slog.Attr)
- func (l *Logger) DebugContext(ctx context.Context, msg string, keyvals ...slog.Attr)
- func (l *Logger) Error(msg string, keyvals ...slog.Attr)
- func (l *Logger) ErrorContext(ctx context.Context, msg string, keyvals ...slog.Attr)
- func (l *Logger) Fatal(msg string, keyvals ...slog.Attr)
- func (l *Logger) FatalContext(ctx context.Context, msg string, keyvals ...slog.Attr)
- func (l *Logger) Info(msg string, keyvals ...slog.Attr)
- func (l *Logger) InfoContext(ctx context.Context, msg string, keyvals ...slog.Attr)
- func (l *Logger) SetLevel(level Level)
- func (l *Logger) Shutdown(reason string)
- func (l *Logger) Warn(msg string, keyvals ...slog.Attr)
- func (l *Logger) WarnContext(ctx context.Context, msg string, keyvals ...slog.Attr)
- func (l *Logger) With(keyvals ...any) *Logger
- type Option
- func WithCaller(enabled bool) Option
- func WithContextExtractor(extractor ContextExtractor) Option
- func WithErrorHandler(handler ErrorHandler) Option
- func WithFields(fields map[string]any) Option
- func WithHook(hook Hook) Option
- func WithLevel(level Level) Option
- func WithSink(s sink.Sink) Option
- func WithTimeFormat(format string) Option
- type SampledLogger
- func (s *SampledLogger) Debug(msg string, keyvals ...slog.Attr)
- func (s *SampledLogger) Error(msg string, keyvals ...slog.Attr)
- func (s *SampledLogger) Fatal(msg string, keyvals ...slog.Attr)
- func (s *SampledLogger) Info(msg string, keyvals ...slog.Attr)
- func (s *SampledLogger) Warn(msg string, keyvals ...slog.Attr)
- type SamplingConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AsyncLogger ¶
type AsyncLogger struct {
*Logger
// contains filtered or unexported fields
}
AsyncLogger wraps a Logger with async capabilities.
func NewAsync ¶
func NewAsync(logger *Logger, opts ...AsyncOption) *AsyncLogger
NewAsync creates a new async logger.
func (*AsyncLogger) BufferLen ¶
func (a *AsyncLogger) BufferLen() int
BufferLen returns the current buffer length.
func (*AsyncLogger) Close ¶
func (a *AsyncLogger) Close() error
Close flushes and closes the async logger.
func (*AsyncLogger) Debug ¶
func (a *AsyncLogger) Debug(msg string, keyvals ...slog.Attr)
Debug logs a debug message asynchronously.
func (*AsyncLogger) DebugContext ¶
DebugContext logs a debug message asynchronously with context.
func (*AsyncLogger) Error ¶
func (a *AsyncLogger) Error(msg string, keyvals ...slog.Attr)
Error logs an error message asynchronously.
func (*AsyncLogger) ErrorContext ¶
ErrorContext logs an error message asynchronously with context.
func (*AsyncLogger) Fatal ¶
func (a *AsyncLogger) Fatal(msg string, keyvals ...slog.Attr)
Fatal logs a fatal message (runs synchronously for safety).
func (*AsyncLogger) Flush ¶
func (a *AsyncLogger) Flush()
Flush waits for all buffered logs to be written.
func (*AsyncLogger) Info ¶
func (a *AsyncLogger) Info(msg string, keyvals ...slog.Attr)
Info logs an info message asynchronously.
func (*AsyncLogger) InfoContext ¶
InfoContext logs an info message asynchronously with context.
func (*AsyncLogger) IsFull ¶
func (a *AsyncLogger) IsFull() bool
IsFull returns true if the buffer is full.
func (*AsyncLogger) Warn ¶
func (a *AsyncLogger) Warn(msg string, keyvals ...slog.Attr)
Warn logs a warning message asynchronously.
func (*AsyncLogger) WarnContext ¶
WarnContext logs a warning message asynchronously with context.
type AsyncOption ¶
type AsyncOption func(*AsyncLogger)
AsyncOption configures an AsyncLogger.
func WithBufferSize ¶
func WithBufferSize(size int) AsyncOption
WithBufferSize sets the buffer size for async logging.
func WithSampling ¶
func WithSampling(config *SamplingConfig) AsyncOption
WithSampling enables log sampling.
func WithShutdownTimeout ¶
func WithShutdownTimeout(d time.Duration) AsyncOption
WithShutdownTimeout sets the timeout for graceful shutdown.
func WithWorkers ¶
func WithWorkers(n int) AsyncOption
WithWorkers sets the number of async workers.
type ContextExtractor ¶
ContextExtractor extracts attributes from a context.
type ErrorHandler ¶
type ErrorHandler func(error)
ErrorHandler is a function that handles errors from sinks.
type Hook ¶
Hook is a function that can intercept and modify log entries. It returns an error if the entry should be dropped or if an error occurred.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is the main logging interface.
func NewFromConfig ¶
NewFromConfig creates a new logger from a YAML configuration file.
func NewFromConfigStruct ¶
NewFromConfigStruct creates a new logger from a config struct.
func (*Logger) DebugContext ¶
DebugContext logs a debug message with context.
func (*Logger) ErrorContext ¶
ErrorContext logs an error message with context.
func (*Logger) FatalContext ¶
FatalContext logs a fatal message with context.
func (*Logger) InfoContext ¶
InfoContext logs an info message with context.
func (*Logger) WarnContext ¶
WarnContext logs a warning message with context.
type Option ¶
type Option func(*Logger)
Option configures a Logger.
func WithCaller ¶
WithCaller enables caller information in log entries.
func WithContextExtractor ¶
func WithContextExtractor(extractor ContextExtractor) Option
WithContextExtractor sets a context extractor.
func WithErrorHandler ¶
func WithErrorHandler(handler ErrorHandler) Option
WithErrorHandler sets the error handler for the logger.
func WithFields ¶
WithFields adds default fields to all log entries.
func WithTimeFormat ¶
WithTimeFormat sets the time format for log entries.
type SampledLogger ¶
type SampledLogger struct {
*Logger
// contains filtered or unexported fields
}
SampledLogger wraps a logger with sampling.
func NewSampled ¶
func NewSampled(logger *Logger, config *SamplingConfig) *SampledLogger
NewSampled creates a logger with sampling.
func (*SampledLogger) Debug ¶
func (s *SampledLogger) Debug(msg string, keyvals ...slog.Attr)
Debug logs with sampling.
func (*SampledLogger) Error ¶
func (s *SampledLogger) Error(msg string, keyvals ...slog.Attr)
Error always logs (no sampling for errors).
func (*SampledLogger) Fatal ¶
func (s *SampledLogger) Fatal(msg string, keyvals ...slog.Attr)
Fatal always logs (no sampling for fatal).
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
advanced_features
command
|
|
|
async
command
|
|
|
basic
command
|
|
|
custom_sink_elasticsearch
command
|
|
|
error_handling
command
|
|
|
file
command
|
|
|
json
command
|
|