Documentation
¶
Index ¶
- Constants
- func CommonEnvironmentEnrichers() []core.LogEventEnricher
- func WithCorrelationId(ctx context.Context, correlationId string) context.Context
- func WithRequestId(ctx context.Context, requestId string) context.Context
- func WithSessionId(ctx context.Context, sessionId string) context.Context
- func WithUserId(ctx context.Context, userId any) context.Context
- type CallersEnricher
- type ContextEnricher
- type ContextValueEnricher
- type CorrelationIdEnricher
- type DeadlineEnricher
- type DeadlineOption
- func WithDeadlineAddProperties(add bool) DeadlineOption
- func WithDeadlineCacheSize(size int) DeadlineOption
- func WithDeadlineCacheTTL(ttl time.Duration) DeadlineOption
- func WithDeadlineCustomHandler(handler func(*core.LogEvent, time.Duration)) DeadlineOption
- func WithDeadlineMetrics(enabled bool) DeadlineOption
- func WithDeadlinePercentageThreshold(percent float64) DeadlineOption
- func WithDeadlineUpgradeLevel(upgrade bool) DeadlineOption
- type EnvironmentEnricher
- type LogContextEnricher
- type MachineNameEnricher
- type ProcessEnricher
- type SourceContextEnricher
- type ThreadIdEnricher
- type ThreadLocalCorrelationIdEnricher
- type TimestampEnricher
Constants ¶
const ( // CorrelationIdKey is the context key for correlation IDs. CorrelationIdKey contextKey = "correlationId" // RequestIdKey is the context key for request IDs. RequestIdKey contextKey = "requestId" // UserIdKey is the context key for user IDs. UserIdKey contextKey = "userId" // SessionIdKey is the context key for session IDs. SessionIdKey contextKey = "sessionId" )
Variables ¶
This section is empty.
Functions ¶
func CommonEnvironmentEnrichers ¶
func CommonEnvironmentEnrichers() []core.LogEventEnricher
CommonEnvironmentEnrichers returns enrichers for common environment variables.
func WithCorrelationId ¶
WithCorrelationId returns a context with a correlation ID.
func WithRequestId ¶
WithRequestId returns a context with a request ID.
func WithSessionId ¶
WithSessionId returns a context with a session ID.
Types ¶
type CallersEnricher ¶
type CallersEnricher struct {
// contains filtered or unexported fields
}
CallersEnricher adds caller information to log events.
func NewCallersEnricher ¶
func NewCallersEnricher(skip int) *CallersEnricher
NewCallersEnricher creates an enricher that adds caller information. skip determines how many stack frames to skip (default should be 6-7 for most logger implementations).
func (*CallersEnricher) Enrich ¶
func (c *CallersEnricher) Enrich(event *core.LogEvent, propertyFactory core.LogEventPropertyFactory)
Enrich adds caller information to the log event.
type ContextEnricher ¶
type ContextEnricher struct {
// contains filtered or unexported fields
}
ContextEnricher enriches log events with values from context.Context.
func NewContextEnricher ¶
func NewContextEnricher(ctx context.Context) *ContextEnricher
NewContextEnricher creates an enricher that extracts values from the given context.
func NewContextEnricherWithKeys ¶
func NewContextEnricherWithKeys(ctx context.Context, propertyKeys map[contextKey]string) *ContextEnricher
NewContextEnricherWithKeys creates an enricher with custom context key mappings.
func (*ContextEnricher) Enrich ¶
func (c *ContextEnricher) Enrich(event *core.LogEvent, propertyFactory core.LogEventPropertyFactory)
Enrich adds context values to the log event.
type ContextValueEnricher ¶
type ContextValueEnricher struct {
// contains filtered or unexported fields
}
ContextValueEnricher enriches log events with a specific value from context.
func NewContextValueEnricher ¶
func NewContextValueEnricher(ctx context.Context, key any, propertyName string) *ContextValueEnricher
NewContextValueEnricher creates an enricher for a specific context value.
func (*ContextValueEnricher) Enrich ¶
func (c *ContextValueEnricher) Enrich(event *core.LogEvent, propertyFactory core.LogEventPropertyFactory)
Enrich adds the context value to the log event.
type CorrelationIdEnricher ¶
type CorrelationIdEnricher struct {
// contains filtered or unexported fields
}
CorrelationIdEnricher adds a correlation ID to all log events. This is useful for tracing requests across multiple services.
func NewCorrelationIdEnricher ¶
func NewCorrelationIdEnricher(correlationId string) *CorrelationIdEnricher
NewCorrelationIdEnricher creates an enricher with a specific correlation ID.
func (*CorrelationIdEnricher) Enrich ¶
func (c *CorrelationIdEnricher) Enrich(event *core.LogEvent, propertyFactory core.LogEventPropertyFactory)
Enrich adds the correlation ID to the log event.
type DeadlineEnricher ¶ added in v0.10.0
type DeadlineEnricher struct {
// contains filtered or unexported fields
}
DeadlineEnricher enriches log events with context deadline information. It detects when operations are approaching context deadlines and adds relevant properties to help diagnose timeout-related issues.
func NewDeadlineEnricher ¶ added in v0.10.0
func NewDeadlineEnricher(threshold time.Duration, opts ...DeadlineOption) *DeadlineEnricher
NewDeadlineEnricher creates a new deadline enricher with the specified threshold.
func (*DeadlineEnricher) Enrich ¶ added in v0.10.0
func (e *DeadlineEnricher) Enrich(event *core.LogEvent, factory core.LogEventPropertyFactory)
Enrich adds deadline information to the log event if context has a deadline.
func (*DeadlineEnricher) EnrichWithContext ¶ added in v0.10.0
func (e *DeadlineEnricher) EnrichWithContext(ctx context.Context, event *core.LogEvent, factory core.LogEventPropertyFactory)
EnrichWithContext enriches the event with deadline information from the provided context. This is used when context is passed explicitly to logging methods.
func (*DeadlineEnricher) Stats ¶ added in v0.10.0
func (e *DeadlineEnricher) Stats() core.DeadlineStats
Stats returns current statistics for monitoring and debugging. This is useful for understanding cache usage and first warning tracking.
type DeadlineOption ¶ added in v0.10.0
type DeadlineOption func(*DeadlineEnricher)
DeadlineOption configures deadline enricher behavior.
func WithDeadlineAddProperties ¶ added in v0.10.0
func WithDeadlineAddProperties(add bool) DeadlineOption
WithDeadlineAddProperties controls whether to add deadline properties to events.
func WithDeadlineCacheSize ¶ added in v0.10.0
func WithDeadlineCacheSize(size int) DeadlineOption
WithDeadlineCacheSize sets the maximum cache size.
func WithDeadlineCacheTTL ¶ added in v0.10.0
func WithDeadlineCacheTTL(ttl time.Duration) DeadlineOption
WithDeadlineCacheTTL sets the cache TTL.
func WithDeadlineCustomHandler ¶ added in v0.10.0
func WithDeadlineCustomHandler(handler func(*core.LogEvent, time.Duration)) DeadlineOption
WithDeadlineCustomHandler sets a custom handler for deadline approaching events.
func WithDeadlineMetrics ¶ added in v0.10.0
func WithDeadlineMetrics(enabled bool) DeadlineOption
WithDeadlineMetrics enables metric emission for deadline approaches.
func WithDeadlinePercentageThreshold ¶ added in v0.10.0
func WithDeadlinePercentageThreshold(percent float64) DeadlineOption
WithDeadlinePercentageThreshold sets a percentage-based threshold. When deadline approaches this percentage of total time, warnings are triggered. For example, 0.1 means warn when 10% of time remains.
func WithDeadlineUpgradeLevel ¶ added in v0.10.0
func WithDeadlineUpgradeLevel(upgrade bool) DeadlineOption
WithDeadlineUpgradeLevel controls whether to upgrade log level when deadline approaches.
type EnvironmentEnricher ¶
type EnvironmentEnricher struct {
// contains filtered or unexported fields
}
EnvironmentEnricher adds environment variable values to log events.
func NewEnvironmentEnricher ¶
func NewEnvironmentEnricher(variableName, propertyName string) *EnvironmentEnricher
NewEnvironmentEnricher creates an enricher that adds the value of an environment variable.
func NewEnvironmentEnricherCached ¶
func NewEnvironmentEnricherCached(variableName, propertyName string) *EnvironmentEnricher
NewEnvironmentEnricherCached creates an enricher that caches the environment variable value.
func (*EnvironmentEnricher) Enrich ¶
func (e *EnvironmentEnricher) Enrich(event *core.LogEvent, propertyFactory core.LogEventPropertyFactory)
Enrich adds the environment variable value to the log event.
type LogContextEnricher ¶ added in v0.3.0
type LogContextEnricher struct {
// contains filtered or unexported fields
}
LogContextEnricher enriches log events with properties from LogContext.
func NewLogContextEnricher ¶ added in v0.3.0
func NewLogContextEnricher(ctx context.Context, getProperties func(context.Context) map[string]any) *LogContextEnricher
NewLogContextEnricher creates an enricher that extracts properties from LogContext.
func (*LogContextEnricher) Enrich ¶ added in v0.3.0
func (e *LogContextEnricher) Enrich(event *core.LogEvent, propertyFactory core.LogEventPropertyFactory)
Enrich adds LogContext properties to the log event.
type MachineNameEnricher ¶
type MachineNameEnricher struct {
// contains filtered or unexported fields
}
MachineNameEnricher adds the machine name to log events.
func NewMachineNameEnricher ¶
func NewMachineNameEnricher() *MachineNameEnricher
NewMachineNameEnricher creates a new machine name enricher.
func NewMachineNameEnricherWithName ¶
func NewMachineNameEnricherWithName(propertyName string) *MachineNameEnricher
NewMachineNameEnricherWithName creates a new machine name enricher with a custom property name.
func (*MachineNameEnricher) Enrich ¶
func (me *MachineNameEnricher) Enrich(event *core.LogEvent, propertyFactory core.LogEventPropertyFactory)
Enrich adds the machine name to the log event.
type ProcessEnricher ¶
type ProcessEnricher struct {
// contains filtered or unexported fields
}
ProcessEnricher adds process information to log events.
func NewProcessEnricher ¶
func NewProcessEnricher() *ProcessEnricher
NewProcessEnricher creates a new process enricher.
func (*ProcessEnricher) Enrich ¶
func (pe *ProcessEnricher) Enrich(event *core.LogEvent, propertyFactory core.LogEventPropertyFactory)
Enrich adds process information to the log event.
type SourceContextEnricher ¶
type SourceContextEnricher struct {
// contains filtered or unexported fields
}
SourceContextEnricher adds the source context (logger name/type) to log events.
func ForSourceContext ¶
func ForSourceContext(sourceContext string) *SourceContextEnricher
ForSourceContext creates a new enricher with the specified source context. This is useful for creating sub-loggers with specific contexts.
func NewAutoSourceContextEnricher ¶
func NewAutoSourceContextEnricher() *SourceContextEnricher
NewAutoSourceContextEnricher creates an enricher that automatically detects the source context.
func NewSourceContextEnricher ¶
func NewSourceContextEnricher(sourceContext string) *SourceContextEnricher
NewSourceContextEnricher creates an enricher that adds the specified source context.
func (*SourceContextEnricher) Enrich ¶
func (e *SourceContextEnricher) Enrich(event *core.LogEvent, propertyFactory core.LogEventPropertyFactory)
Enrich adds the source context to the log event.
type ThreadIdEnricher ¶
type ThreadIdEnricher struct{}
ThreadIdEnricher adds the current goroutine ID to log events. Note: Go doesn't expose goroutine IDs officially, so this uses a workaround.
func NewThreadIdEnricher ¶
func NewThreadIdEnricher() *ThreadIdEnricher
NewThreadIdEnricher creates a new thread ID enricher.
func (*ThreadIdEnricher) Enrich ¶
func (t *ThreadIdEnricher) Enrich(event *core.LogEvent, propertyFactory core.LogEventPropertyFactory)
Enrich adds the goroutine ID to the log event.
type ThreadLocalCorrelationIdEnricher ¶
type ThreadLocalCorrelationIdEnricher struct {
// contains filtered or unexported fields
}
ThreadLocalCorrelationIdEnricher uses goroutine-local storage for correlation IDs. Note: This is a simplified implementation. In production, you might want to use a proper goroutine-local storage library or pass correlation IDs explicitly.
func NewThreadLocalCorrelationIdEnricher ¶
func NewThreadLocalCorrelationIdEnricher() *ThreadLocalCorrelationIdEnricher
NewThreadLocalCorrelationIdEnricher creates a new thread-local correlation ID enricher.
func (*ThreadLocalCorrelationIdEnricher) ClearCorrelationId ¶
func (t *ThreadLocalCorrelationIdEnricher) ClearCorrelationId()
ClearCorrelationId clears the correlation ID for the current goroutine.
func (*ThreadLocalCorrelationIdEnricher) Enrich ¶
func (t *ThreadLocalCorrelationIdEnricher) Enrich(event *core.LogEvent, propertyFactory core.LogEventPropertyFactory)
Enrich adds the correlation ID for the current goroutine to the log event.
func (*ThreadLocalCorrelationIdEnricher) SetCorrelationId ¶
func (t *ThreadLocalCorrelationIdEnricher) SetCorrelationId(correlationId string)
SetCorrelationId sets the correlation ID for the current goroutine.
type TimestampEnricher ¶
type TimestampEnricher struct {
// contains filtered or unexported fields
}
TimestampEnricher adds a high-precision timestamp to log events.
func NewTimestampEnricher ¶
func NewTimestampEnricher() *TimestampEnricher
NewTimestampEnricher creates a new timestamp enricher.
func NewTimestampEnricherWithName ¶
func NewTimestampEnricherWithName(propertyName string) *TimestampEnricher
NewTimestampEnricherWithName creates a new timestamp enricher with a custom property name.
func (*TimestampEnricher) Enrich ¶
func (te *TimestampEnricher) Enrich(event *core.LogEvent, propertyFactory core.LogEventPropertyFactory)
Enrich adds the current timestamp to the log event.