Documentation
¶
Index ¶
- func New(opts ...Option) *logger
- func NewLogrLogger(options ...Option) logr.Logger
- func NewSlogLogger(options ...Option) *slog.Logger
- func WithControlledLevel(initialLevel core.LogEventLevel) (Option, *LoggingLevelSwitch)
- func WithSeqLevelControl(serverURL string, options SeqLevelControllerOptions, ...) (Option, *LoggingLevelSwitch, *SeqLevelController)
- type LogBuilder
- func (b *LogBuilder) Level(level core.LogEventLevel) *LogBuilder
- func (b *LogBuilder) Message(template string) *LogBuilder
- func (b *LogBuilder) Property(name string, value interface{}) *LogBuilder
- func (b *LogBuilder) PropertyTyped(name string, value interface{}) *LogBuilder
- func (b *LogBuilder) Write()
- type LoggerG
- type LoggingLevelSwitch
- func (ls *LoggingLevelSwitch) Debug() *LoggingLevelSwitch
- func (ls *LoggingLevelSwitch) Error() *LoggingLevelSwitch
- func (ls *LoggingLevelSwitch) Fatal() *LoggingLevelSwitch
- func (ls *LoggingLevelSwitch) Information() *LoggingLevelSwitch
- func (ls *LoggingLevelSwitch) IsEnabled(level core.LogEventLevel) bool
- func (ls *LoggingLevelSwitch) Level() core.LogEventLevel
- func (ls *LoggingLevelSwitch) SetLevel(level core.LogEventLevel)
- func (ls *LoggingLevelSwitch) Verbose() *LoggingLevelSwitch
- func (ls *LoggingLevelSwitch) Warning() *LoggingLevelSwitch
- type Option
- func Debug() Option
- func Error() Option
- func Information() Option
- func Verbose() Option
- func Warning() Option
- func WithCallers(skip int) Option
- func WithCallersInfo() Option
- func WithCommonEnvironment() Option
- func WithConsole() Option
- func WithConsoleProperties() Option
- func WithCorrelationId(correlationId string) Option
- func WithCustomDestructuring(maxDepth, maxStringLength, maxCollectionCount int) Option
- func WithDestructurer(destructurer core.Destructurer) Option
- func WithDestructuring() Option
- func WithDestructuringDepth(maxDepth int) Option
- func WithDurableBuffer(wrapped core.LogEventSink, bufferPath string) Option
- func WithDurableBufferAdvanced(wrapped core.LogEventSink, options sinks.DurableOptions) Option
- func WithDurableElasticsearch(url, bufferPath string) Option
- func WithDurableSeq(serverURL, bufferPath string) Option
- func WithDurableSplunk(url, token, bufferPath string) Option
- func WithDynamicLevel(levelSwitch *LoggingLevelSwitch) Option
- func WithElasticsearch(url string) Option
- func WithElasticsearchAPIKey(url, apiKey string) Option
- func WithElasticsearchAdvanced(url string, opts ...sinks.ElasticsearchOption) Option
- func WithElasticsearchBasicAuth(url, username, password string) Option
- func WithEnricher(enricher core.LogEventEnricher) Option
- func WithEnvironment(variableName, propertyName string) Option
- func WithEnvironmentVariables(variables ...string) Option
- func WithExcludeFilter(predicate func(*core.LogEvent) bool) Option
- func WithFile(path string) Option
- func WithFilter(filter core.LogEventFilter) Option
- func WithHashSampling(propertyName string, rate float32) Option
- func WithLevelFilter(minimumLevel core.LogEventLevel) Option
- func WithLevelSwitch(levelSwitch *LoggingLevelSwitch) Option
- func WithMachineName() Option
- func WithMinimumLevel(level core.LogEventLevel) Option
- func WithProcess() Option
- func WithProcessInfo() Option
- func WithProperties(properties map[string]interface{}) Option
- func WithProperty(name string, value interface{}) Option
- func WithPropertyFilter(propertyName string, expectedValue interface{}) Option
- func WithRateLimit(maxEvents int, windowNanos int64) Option
- func WithSampling(rate float32) Option
- func WithSeq(serverURL string) Option
- func WithSeqAPIKey(serverURL, apiKey string) Option
- func WithSeqAdvanced(serverURL string, opts ...sinks.SeqOption) Option
- func WithSink(sink core.LogEventSink) Option
- func WithSplunk(url, token string) Option
- func WithSplunkAdvanced(url, token string, opts ...sinks.SplunkOption) Option
- func WithThreadId() Option
- func WithTimestamp() Option
- type SeqLevelController
- type SeqLevelControllerBuilder
- func (b *SeqLevelControllerBuilder) Build() (Option, *LoggingLevelSwitch, *SeqLevelController)
- func (b *SeqLevelControllerBuilder) WithCheckInterval(interval time.Duration) *SeqLevelControllerBuilder
- func (b *SeqLevelControllerBuilder) WithErrorHandler(onError func(error)) *SeqLevelControllerBuilder
- func (b *SeqLevelControllerBuilder) WithInitialCheck(initialCheck bool) *SeqLevelControllerBuilder
- func (b *SeqLevelControllerBuilder) WithLevelSwitch(levelSwitch *LoggingLevelSwitch) *SeqLevelControllerBuilder
- func (b *SeqLevelControllerBuilder) WithSeqAPIKey(apiKey string) *SeqLevelControllerBuilder
- type SeqLevelControllerOptions
- type StructuredLogger
- type TypedLogger
- func (l *TypedLogger[T]) DebugT(messageTemplate string, value T, args ...interface{})
- func (l *TypedLogger[T]) ErrorT(messageTemplate string, value T, args ...interface{})
- func (l *TypedLogger[T]) FatalT(messageTemplate string, value T, args ...interface{})
- func (l *TypedLogger[T]) ForContextT(propertyName string, value T) LoggerG[T]
- func (l *TypedLogger[T]) InfoT(messageTemplate string, value T, args ...interface{})
- func (l *TypedLogger[T]) InformationT(messageTemplate string, value T, args ...interface{})
- func (l *TypedLogger[T]) VerboseT(messageTemplate string, value T, args ...interface{})
- func (l *TypedLogger[T]) WarnT(messageTemplate string, value T, args ...interface{})
- func (l *TypedLogger[T]) WarningT(messageTemplate string, value T, args ...interface{})
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewLogrLogger ¶
NewLogrLogger creates a new logr.Logger backed by mtlog
func NewSlogLogger ¶
NewSlogLogger creates a new slog.Logger backed by mtlog
func WithControlledLevel ¶
func WithControlledLevel(initialLevel core.LogEventLevel) (Option, *LoggingLevelSwitch)
WithControlledLevel creates a level switch and applies it to the logger. Returns both the option and the level switch for external control.
func WithSeqLevelControl ¶
func WithSeqLevelControl(serverURL string, options SeqLevelControllerOptions, seqOptions ...sinks.SeqOption) (Option, *LoggingLevelSwitch, *SeqLevelController)
WithSeqLevelControl creates a logger with Seq-controlled dynamic level adjustment. This convenience function sets up both a Seq sink and automatic level control.
Types ¶
type LogBuilder ¶
type LogBuilder struct {
// contains filtered or unexported fields
}
LogBuilder provides a fluent API for building typed log entries
func (*LogBuilder) Level ¶
func (b *LogBuilder) Level(level core.LogEventLevel) *LogBuilder
Level sets the log level
func (*LogBuilder) Message ¶
func (b *LogBuilder) Message(template string) *LogBuilder
Message sets the message template
func (*LogBuilder) Property ¶
func (b *LogBuilder) Property(name string, value interface{}) *LogBuilder
Property adds a property
func (*LogBuilder) PropertyTyped ¶
func (b *LogBuilder) PropertyTyped(name string, value interface{}) *LogBuilder
PropertyTyped adds a typed property
type LoggerG ¶
type LoggerG[T any] interface { // Logging methods with type safety VerboseT(messageTemplate string, value T, args ...interface{}) DebugT(messageTemplate string, value T, args ...interface{}) InformationT(messageTemplate string, value T, args ...interface{}) WarningT(messageTemplate string, value T, args ...interface{}) ErrorT(messageTemplate string, value T, args ...interface{}) FatalT(messageTemplate string, value T, args ...interface{}) // Short method names InfoT(messageTemplate string, value T, args ...interface{}) WarnT(messageTemplate string, value T, args ...interface{}) // ForContextT adds a typed property ForContextT(propertyName string, value T) LoggerG[T] }
LoggerG is a generic type-safe logger interface
type LoggingLevelSwitch ¶
type LoggingLevelSwitch struct {
// contains filtered or unexported fields
}
LoggingLevelSwitch provides thread-safe, runtime control of the minimum log level. It enables dynamic adjustment of logging levels without restarting the application.
func NewLoggingLevelSwitch ¶
func NewLoggingLevelSwitch(initialLevel core.LogEventLevel) *LoggingLevelSwitch
NewLoggingLevelSwitch creates a new logging level switch with the specified initial level.
func (*LoggingLevelSwitch) Debug ¶
func (ls *LoggingLevelSwitch) Debug() *LoggingLevelSwitch
Debug sets the minimum level to Debug.
func (*LoggingLevelSwitch) Error ¶
func (ls *LoggingLevelSwitch) Error() *LoggingLevelSwitch
Error sets the minimum level to Error.
func (*LoggingLevelSwitch) Fatal ¶
func (ls *LoggingLevelSwitch) Fatal() *LoggingLevelSwitch
Fatal sets the minimum level to Fatal.
func (*LoggingLevelSwitch) Information ¶
func (ls *LoggingLevelSwitch) Information() *LoggingLevelSwitch
Information sets the minimum level to Information.
func (*LoggingLevelSwitch) IsEnabled ¶
func (ls *LoggingLevelSwitch) IsEnabled(level core.LogEventLevel) bool
IsEnabled returns true if the specified level would be processed with the current minimum level setting.
func (*LoggingLevelSwitch) Level ¶
func (ls *LoggingLevelSwitch) Level() core.LogEventLevel
Level returns the current minimum log level.
func (*LoggingLevelSwitch) SetLevel ¶
func (ls *LoggingLevelSwitch) SetLevel(level core.LogEventLevel)
SetLevel updates the minimum log level. This operation is thread-safe and takes effect immediately.
func (*LoggingLevelSwitch) Verbose ¶
func (ls *LoggingLevelSwitch) Verbose() *LoggingLevelSwitch
Verbose sets the minimum level to Verbose.
func (*LoggingLevelSwitch) Warning ¶
func (ls *LoggingLevelSwitch) Warning() *LoggingLevelSwitch
Warning sets the minimum level to Warning.
type Option ¶
type Option func(*config)
Option is a functional option for configuring a logger.
func WithCallers ¶
WithCallers adds caller information enrichment.
func WithCallersInfo ¶
func WithCallersInfo() Option
WithCallersInfo adds caller information enrichment with default skip.
func WithCommonEnvironment ¶
func WithCommonEnvironment() Option
WithCommonEnvironment adds enrichers for common environment variables.
func WithConsoleProperties ¶
func WithConsoleProperties() Option
WithConsoleProperties adds a console sink that displays properties.
func WithCorrelationId ¶
WithCorrelationId adds a fixed correlation ID to all log events.
func WithCustomDestructuring ¶
WithCustomDestructuring adds a destructurer with custom limits.
func WithDestructurer ¶
func WithDestructurer(destructurer core.Destructurer) Option
WithDestructurer sets the destructurer for the pipeline.
func WithDestructuring ¶
func WithDestructuring() Option
WithDestructuring adds the cached destructurer for better performance.
func WithDestructuringDepth ¶
WithDestructuringDepth adds destructuring with a specific max depth.
func WithDurableBuffer ¶
func WithDurableBuffer(wrapped core.LogEventSink, bufferPath string) Option
WithDurableBuffer adds durable buffering to a sink for reliability.
func WithDurableBufferAdvanced ¶
func WithDurableBufferAdvanced(wrapped core.LogEventSink, options sinks.DurableOptions) Option
WithDurableBufferAdvanced adds durable buffering with advanced options.
func WithDurableElasticsearch ¶
WithDurableElasticsearch adds an Elasticsearch sink with durable buffering.
func WithDurableSeq ¶
WithDurableSeq adds a Seq sink with durable buffering.
func WithDurableSplunk ¶
WithDurableSplunk adds a Splunk sink with durable buffering.
func WithDynamicLevel ¶
func WithDynamicLevel(levelSwitch *LoggingLevelSwitch) Option
WithDynamicLevel enables dynamic level control using a level switch. This is an alias for WithLevelSwitch for better readability.
func WithElasticsearch ¶
WithElasticsearch adds an Elasticsearch sink with default configuration.
func WithElasticsearchAPIKey ¶
WithElasticsearchAPIKey adds an Elasticsearch sink with API key authentication.
func WithElasticsearchAdvanced ¶
func WithElasticsearchAdvanced(url string, opts ...sinks.ElasticsearchOption) Option
WithElasticsearchAdvanced adds an Elasticsearch sink with advanced options.
func WithElasticsearchBasicAuth ¶
WithElasticsearchBasicAuth adds an Elasticsearch sink with basic authentication.
func WithEnricher ¶
func WithEnricher(enricher core.LogEventEnricher) Option
WithEnricher adds an enricher to the pipeline.
func WithEnvironment ¶
WithEnvironment adds environment variable enrichment.
func WithEnvironmentVariables ¶
WithEnvironmentVariables adds enrichers for multiple environment variables.
func WithExcludeFilter ¶
WithExcludeFilter adds a filter that excludes events matching the predicate.
func WithFilter ¶
func WithFilter(filter core.LogEventFilter) Option
WithFilter adds a filter to the pipeline.
func WithHashSampling ¶
WithHashSampling adds a hash-based sampling filter.
func WithLevelFilter ¶
func WithLevelFilter(minimumLevel core.LogEventLevel) Option
WithLevelFilter adds a minimum level filter.
func WithLevelSwitch ¶
func WithLevelSwitch(levelSwitch *LoggingLevelSwitch) Option
WithLevelSwitch enables dynamic level control using the specified level switch. When a level switch is provided, it takes precedence over the static minimum level.
func WithMinimumLevel ¶
func WithMinimumLevel(level core.LogEventLevel) Option
WithMinimumLevel sets the minimum log level.
func WithProperties ¶
WithProperties adds multiple global properties.
func WithProperty ¶
WithProperty adds a global property to all log events.
func WithPropertyFilter ¶
WithPropertyFilter adds a filter that matches a specific property value.
func WithRateLimit ¶
WithRateLimit adds a rate limiting filter.
func WithSeqAPIKey ¶
WithSeqAPIKey adds a Seq sink with API key authentication.
func WithSeqAdvanced ¶
WithSeqAdvanced adds a Seq sink with advanced options.
func WithSplunk ¶
WithSplunk adds a Splunk sink to the logger.
func WithSplunkAdvanced ¶
func WithSplunkAdvanced(url, token string, opts ...sinks.SplunkOption) Option
WithSplunkAdvanced adds a Splunk sink with advanced options.
type SeqLevelController ¶
type SeqLevelController struct {
// contains filtered or unexported fields
}
SeqLevelController automatically updates a LoggingLevelSwitch based on the minimum level configured in Seq. This enables centralized level control where Seq acts as the source of truth for log levels.
func NewSeqLevelController ¶
func NewSeqLevelController(levelSwitch *LoggingLevelSwitch, seqSink *sinks.SeqSink, options SeqLevelControllerOptions) *SeqLevelController
NewSeqLevelController creates a new controller that synchronizes a level switch with Seq's minimum level setting. The controller will periodically query Seq and update the level switch when changes are detected.
func (*SeqLevelController) Close ¶
func (slc *SeqLevelController) Close()
Close stops the level controller and waits for background operations to complete.
func (*SeqLevelController) ForceCheck ¶
func (slc *SeqLevelController) ForceCheck() error
ForceCheck immediately queries Seq for the current level and updates the level switch if necessary. This is useful for testing or immediate synchronization.
func (*SeqLevelController) GetCurrentLevel ¶
func (slc *SeqLevelController) GetCurrentLevel() core.LogEventLevel
GetCurrentLevel returns the current level from the level switch.
func (*SeqLevelController) GetLastSeqLevel ¶
func (slc *SeqLevelController) GetLastSeqLevel() core.LogEventLevel
GetLastSeqLevel returns the last level retrieved from Seq.
type SeqLevelControllerBuilder ¶
type SeqLevelControllerBuilder struct {
// contains filtered or unexported fields
}
SeqLevelControllerBuilder provides a fluent interface for building Seq level controllers.
func NewSeqLevelControllerBuilder ¶
func NewSeqLevelControllerBuilder(serverURL string) *SeqLevelControllerBuilder
NewSeqLevelControllerBuilder creates a new builder for Seq level controllers.
func (*SeqLevelControllerBuilder) Build ¶
func (b *SeqLevelControllerBuilder) Build() (Option, *LoggingLevelSwitch, *SeqLevelController)
Build creates the Seq level controller and returns the logger option, level switch, and controller.
func (*SeqLevelControllerBuilder) WithCheckInterval ¶
func (b *SeqLevelControllerBuilder) WithCheckInterval(interval time.Duration) *SeqLevelControllerBuilder
WithCheckInterval sets the interval for querying Seq.
func (*SeqLevelControllerBuilder) WithErrorHandler ¶
func (b *SeqLevelControllerBuilder) WithErrorHandler(onError func(error)) *SeqLevelControllerBuilder
WithErrorHandler sets the error handler for level checking failures.
func (*SeqLevelControllerBuilder) WithInitialCheck ¶
func (b *SeqLevelControllerBuilder) WithInitialCheck(initialCheck bool) *SeqLevelControllerBuilder
WithInitialCheck controls whether to perform an initial level check.
func (*SeqLevelControllerBuilder) WithLevelSwitch ¶
func (b *SeqLevelControllerBuilder) WithLevelSwitch(levelSwitch *LoggingLevelSwitch) *SeqLevelControllerBuilder
WithLevelSwitch uses an existing level switch instead of creating a new one.
func (*SeqLevelControllerBuilder) WithSeqAPIKey ¶
func (b *SeqLevelControllerBuilder) WithSeqAPIKey(apiKey string) *SeqLevelControllerBuilder
WithSeqAPIKey adds API key authentication for Seq.
type SeqLevelControllerOptions ¶
type SeqLevelControllerOptions struct {
// CheckInterval is how often to query Seq for level changes.
// Default: 30 seconds
CheckInterval time.Duration
// OnError is called when an error occurs during level checking.
// Default: no-op
OnError func(error)
// InitialCheck determines whether to perform an initial check immediately.
// Default: true
InitialCheck bool
}
SeqLevelControllerOptions configures a Seq level controller.
type StructuredLogger ¶
type StructuredLogger struct {
// contains filtered or unexported fields
}
StructuredLogger provides type-safe structured logging
func NewStructured ¶
func NewStructured(opts ...Option) *StructuredLogger
NewStructured creates a new structured logger
func (*StructuredLogger) Log ¶
func (sl *StructuredLogger) Log(level core.LogEventLevel, messageTemplate string, properties *core.PropertyBag)
Log logs with a typed property bag
func (*StructuredLogger) LogWith ¶
func (sl *StructuredLogger) LogWith() *LogBuilder
LogWith logs with typed properties using a builder pattern
type TypedLogger ¶
type TypedLogger[T any] struct { // contains filtered or unexported fields }
TypedLogger wraps a regular logger with type-safe methods
func (*TypedLogger[T]) DebugT ¶
func (l *TypedLogger[T]) DebugT(messageTemplate string, value T, args ...interface{})
DebugT logs at debug level with typed value
func (*TypedLogger[T]) ErrorT ¶
func (l *TypedLogger[T]) ErrorT(messageTemplate string, value T, args ...interface{})
ErrorT logs at error level with typed value
func (*TypedLogger[T]) FatalT ¶
func (l *TypedLogger[T]) FatalT(messageTemplate string, value T, args ...interface{})
FatalT logs at fatal level with typed value
func (*TypedLogger[T]) ForContextT ¶
func (l *TypedLogger[T]) ForContextT(propertyName string, value T) LoggerG[T]
ForContextT adds a typed property to the logger context
func (*TypedLogger[T]) InfoT ¶
func (l *TypedLogger[T]) InfoT(messageTemplate string, value T, args ...interface{})
InfoT writes an information-level log event with a typed value (alias for InformationT)
func (*TypedLogger[T]) InformationT ¶
func (l *TypedLogger[T]) InformationT(messageTemplate string, value T, args ...interface{})
InformationT logs at information level with typed value
func (*TypedLogger[T]) VerboseT ¶
func (l *TypedLogger[T]) VerboseT(messageTemplate string, value T, args ...interface{})
VerboseT logs at verbose level with typed value
func (*TypedLogger[T]) WarnT ¶
func (l *TypedLogger[T]) WarnT(messageTemplate string, value T, args ...interface{})
WarnT writes a warning-level log event with a typed value (alias for WarningT)
func (*TypedLogger[T]) WarningT ¶
func (l *TypedLogger[T]) WarningT(messageTemplate string, value T, args ...interface{})
WarningT logs at warning level with typed value
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
adapters
|
|
|
otel
module
|
|
|
sentry
module
|
|
|
cmd
|
|
|
mtlog-analyzer
module
|
|
|
Package core provides the fundamental interfaces and types for mtlog.
|
Package core provides the fundamental interfaces and types for mtlog. |
|
examples
|
|
|
async
command
|
|
|
basic
command
|
|
|
configuration
command
|
|
|
context
command
|
|
|
destructuring
command
|
|
|
durable
command
|
|
|
dynamic-levels
command
|
|
|
elasticsearch
command
|
|
|
enrichers
command
|
|
|
filtering
command
|
|
|
generics
command
|
|
|
logvalue
command
|
|
|
rolling
command
|
|
|
seq
command
|
|
|
splunk
command
|
|
|
themes
command
|
|