Documentation
¶
Index ¶
- Constants
- Variables
- func AddFieldPathRule(logger interface{}, path, replacement string)
- func ClearFieldPathRules(logger interface{})
- func ClearRedactionCache(logger interface{})
- func CompressionTypeString(ct CompressionType) string
- func EnableRedactionForLevel(logger interface{}, level int, enable bool)
- func GetReplacementForPath(path string, fieldPathRules []FieldPathRule) string
- func IsSensitiveKey(key string) bool
- func LogRequest(logger interface{}, method, path string, headers map[string][]string, ...)
- func LogResponse(logger interface{}, statusCode int, headers map[string][]string, body string)
- func MatchesPath(path, pattern string) bool
- func RecursiveRedact(v interface{}, currentPath string, redactor *Redactor, ...)
- func RecursiveRedactWithSkip(v interface{}, currentPath string, redactor *Redactor, ...)
- func RedactSensitive(input string, config *RedactionConfig, redactor *Redactor, ...) string
- func RedactSensitiveWithLevel(input string, level int, config *RedactionConfig, redactor *Redactor, ...) string
- func RegexRedact(input string, redactor *Redactor) string
- func RemoveFieldPathRule(logger interface{}, path string)
- func SetRedaction(logger interface{}, patterns []string, replace string) error
- func SetRedactionConfig(logger interface{}, config *RedactionConfig)
- func ShouldRedactPath(path string, fieldPathRules []FieldPathRule) bool
- type AdaptiveSampler
- type AdaptiveWindow
- type BurstTracker
- type ChainMode
- type CompressibleLogger
- type CompressionConfig
- type CompressionManager
- func (c *CompressionManager) CompressFileSync(path string) error
- func (c *CompressionManager) GetMinAge() int
- func (c *CompressionManager) GetStatus() CompressionStatus
- func (c *CompressionManager) GetType() CompressionType
- func (c *CompressionManager) QueueFile(path string)
- func (c *CompressionManager) SetCompression(compressionType CompressionType) error
- func (c *CompressionManager) SetErrorHandler(handler func(source, dest, msg string, err error))
- func (c *CompressionManager) SetMetricsHandler(handler func(string))
- func (c *CompressionManager) SetMinAge(age int)
- func (c *CompressionManager) SetWorkers(workers int)
- func (c *CompressionManager) Start()
- func (c *CompressionManager) Stop()
- type CompressionStatus
- type CompressionType
- type Compressor
- type ContextualRule
- type FieldPathRule
- type FieldRedactionRule
- type Filter
- type FilterCache
- type FilterChain
- type FilterFunc
- func CreateCompositeFilter(filters ...FilterFunc) FilterFunc
- func CreateExcludeRegexFilter(pattern *regexp.Regexp) FilterFunc
- func CreateFieldExistsFilter(field string) FilterFunc
- func CreateFieldFilter(field string, values ...interface{}) FilterFunc
- func CreateFieldNotExistsFilter(field string) FilterFunc
- func CreateFieldPrefixFilter(prefix string) FilterFunc
- func CreateFieldRangeFilter(field string, min, max float64) FilterFunc
- func CreateLevelFieldFilter(logLevel int, field string, value interface{}) FilterFunc
- func CreateLevelFilter(minLevel int) FilterFunc
- func CreateMultiFieldFilter(fields ...string) FilterFunc
- func CreateNotFilter(filter FilterFunc) FilterFunc
- func CreateOrFilter(filters ...FilterFunc) FilterFunc
- func CreateRateLimitFilter(maxPerSecond float64) FilterFunc
- func CreateRegexFilter(pattern *regexp.Regexp) FilterFunc
- func CreateTimeWindowFilter(startHour, endHour int) FilterFunc
- type FilterManager
- func (f *FilterManager) AddFilter(filter FilterFunc) error
- func (f *FilterManager) AddFilterChain(chain *FilterChain) error
- func (f *FilterManager) AddNamedFilter(name, description string, filter FilterFunc, priority int) error
- func (f *FilterManager) ApplyFilters(level int, message string, fields map[string]interface{}) bool
- func (f *FilterManager) ClearFilters()
- func (f *FilterManager) DisableCache()
- func (f *FilterManager) DisableFilter(name string) error
- func (f *FilterManager) EnableCache(maxSize int, ttl time.Duration)
- func (f *FilterManager) EnableFilter(name string) error
- func (f *FilterManager) Get(name string) (*NamedFilter, bool)
- func (f *FilterManager) GetFilterCount() int
- func (f *FilterManager) GetMetrics() FilterMetrics
- func (f *FilterManager) GetStatus() FilterStatus
- func (f *FilterManager) List() []NamedFilter
- func (f *FilterManager) ListChains() map[string]*FilterChain
- func (f *FilterManager) RemoveFilter(name string) error
- func (f *FilterManager) RemoveFilterChain(name string) error
- func (f *FilterManager) ResetMetrics()
- func (f *FilterManager) SetErrorHandler(handler func(source, dest, msg string, err error))
- func (f *FilterManager) SetMetricsHandler(handler func(string))
- type FilterMetrics
- type FilterStatus
- type FilterableLogger
- type FullFeaturedLogger
- type LevelFilter
- type Logger
- type MetricsLogger
- type NamedFilter
- type PatternSamplingRule
- type RateLimiter
- type RecoverableLogger
- type Recovery
- type RecoveryConfig
- type RecoveryManager
- func (rm *RecoveryManager) Close() error
- func (rm *RecoveryManager) FlushBuffer(processFunc func(message interface{}) error) error
- func (rm *RecoveryManager) GetBufferSize() int
- func (rm *RecoveryManager) GetConfig() *RecoveryConfig
- func (rm *RecoveryManager) GetRetryCount(destName string) int
- func (rm *RecoveryManager) HandleError(err error, message interface{}, destName string, writeFunc func() error)
- func (rm *RecoveryManager) ResetRetryCount(destName string)
- func (rm *RecoveryManager) SetErrorHandler(handler func(source, dest, msg string, err error))
- func (rm *RecoveryManager) SetMetricsHandler(handler func(event string))
- func (rm *RecoveryManager) UpdateConfig(config *RecoveryConfig)
- type RecoveryStrategy
- type RedactableLogger
- type RedactionCache
- type RedactionConfig
- type RedactionManager
- func (rm *RedactionManager) AddContextualRule(rule ContextualRule)
- func (rm *RedactionManager) AddFieldPathRule(rule FieldPathRule)
- func (rm *RedactionManager) GetMetrics() RedactionMetrics
- func (rm *RedactionManager) RedactMessage(level int, message string, fields map[string]interface{}) (string, map[string]interface{})
- func (rm *RedactionManager) RemoveFieldPathRule(path string)
- func (rm *RedactionManager) SetConfig(config *RedactionConfig)
- func (rm *RedactionManager) SetCustomRedactor(redactor *Redactor)
- func (rm *RedactionManager) SetErrorHandler(handler func(source, dest, msg string, err error))
- func (rm *RedactionManager) SetMetricsHandler(handler func(string))
- type RedactionMetrics
- type RedactionMode
- type Redactor
- type RedactorInterface
- type RegexFilter
- type RotatableLogger
- type RotatedFileInfo
- type RotationConfig
- type RotationManager
- func (r *RotationManager) AddLogPath(path string)
- func (r *RotationManager) CleanupOldFiles(logPath string) error
- func (r *RotationManager) CleanupOldLogs(logPath string) error
- func (r *RotationManager) GetCleanupInterval() time.Duration
- func (r *RotationManager) GetMaxAge() time.Duration
- func (r *RotationManager) GetMaxFiles() int
- func (r *RotationManager) GetRotatedFiles(logPath string) ([]RotatedFileInfo, error)
- func (r *RotationManager) GetStatus() RotationStatus
- func (r *RotationManager) IsRunning() bool
- func (r *RotationManager) RemoveLogPath(path string)
- func (r *RotationManager) RotateFile(path string, writer *bufio.Writer) (string, error)
- func (r *RotationManager) RunCleanup(logPath string) error
- func (r *RotationManager) SetCleanupInterval(interval time.Duration)
- func (r *RotationManager) SetCompressionCallback(callback func(path string))
- func (r *RotationManager) SetErrorHandler(handler func(source, dest, msg string, err error))
- func (r *RotationManager) SetMaxAge(duration time.Duration) error
- func (r *RotationManager) SetMaxFiles(count int)
- func (r *RotationManager) SetMetricsHandler(handler func(string))
- func (r *RotationManager) Start()
- func (r *RotationManager) Stop()
- type RotationStatus
- type Rotator
- type SamplableLogger
- type Sampler
- type SamplingConfig
- type SamplingManager
- func (s *SamplingManager) ExportMetrics() SamplingMetricsExport
- func (s *SamplingManager) GetMetrics() SamplingMetrics
- func (s *SamplingManager) GetRate() float64
- func (s *SamplingManager) GetStatus() SamplingStatus
- func (s *SamplingManager) GetStrategy() SamplingStrategy
- func (s *SamplingManager) Reset()
- func (s *SamplingManager) SetAdaptiveConfig(targetRate, minRate, maxRate float64, windowSize time.Duration)
- func (s *SamplingManager) SetBurstConfig(window time.Duration, burstSize int)
- func (s *SamplingManager) SetErrorHandler(handler func(source, dest, msg string, err error))
- func (s *SamplingManager) SetKeyFunc(keyFunc func(level int, message string, fields map[string]interface{}) string)
- func (s *SamplingManager) SetLevelSampling(levelRates map[int]float64)
- func (s *SamplingManager) SetMetricsHandler(handler func(string))
- func (s *SamplingManager) SetPatternRules(rules []PatternSamplingRule) error
- func (s *SamplingManager) SetStrategy(strategy SamplingStrategy, rate float64) error
- func (s *SamplingManager) ShouldLog(level int, message string, fields map[string]interface{}) bool
- type SamplingMetrics
- type SamplingMetricsExport
- type SamplingStatus
- type SamplingStrategy
- type StructuredLogger
Constants ¶
const RotationTimeFormat = "20060102-150405.000"
RotationTimeFormat is the timestamp format used for rotated log files. The format is sortable and includes millisecond precision to avoid collisions. Example: "20060102-150405.000" produces "20240115-143052.123"
Variables ¶
var ErrNilFilter = errors.New("filter cannot be nil")
ErrNilFilter is returned when a nil filter is passed
Functions ¶
func AddFieldPathRule ¶
func AddFieldPathRule(logger interface{}, path, replacement string)
AddFieldPathRule adds a field path rule for targeted redaction.
Note: This function provides the interface but the actual implementation should be in the omni package where private fields can be accessed.
Parameters:
- logger: The Omni logger instance (interface{})
- path: JSON field path like "user.profile.ssn" or "users.*.email"
- replacement: Custom replacement text for this path
Example:
features.AddFieldPathRule(logger, "user.profile.ssn", "[SSN-REDACTED]") features.AddFieldPathRule(logger, "users.*.email", "[EMAIL-REDACTED]")
func ClearFieldPathRules ¶
func ClearFieldPathRules(logger interface{})
ClearFieldPathRules removes all field path rules.
Note: This function provides the interface but the actual implementation should be in the omni package where private fields can be accessed.
func ClearRedactionCache ¶
func ClearRedactionCache(logger interface{})
ClearRedactionCache clears the redaction cache to free memory.
Note: This function provides the interface but the actual implementation should be in the omni package where private fields can be accessed.
func CompressionTypeString ¶
func CompressionTypeString(ct CompressionType) string
CompressionTypeString returns the string representation of a compression type
func EnableRedactionForLevel ¶
EnableRedactionForLevel enables or disables redaction for a specific log level.
Note: This function provides the interface but the actual implementation should be in the omni package where private fields can be accessed.
Parameters:
- logger: The Omni logger instance (interface{})
- level: The log level to configure
- enable: Whether to enable redaction for this level
func GetReplacementForPath ¶
func GetReplacementForPath(path string, fieldPathRules []FieldPathRule) string
GetReplacementForPath gets the replacement text for a specific field path
func IsSensitiveKey ¶
IsSensitiveKey checks if a key is considered sensitive. It performs case-insensitive matching against known sensitive keywords.
Parameters:
- key: The field name to check
Returns:
- bool: true if the key is sensitive
func LogRequest ¶
LogRequest logs an API request with automatic redaction of sensitive data. It redacts authorization headers and sensitive fields in the request body.
Note: This function provides the interface but the actual implementation should be in the omni package where private fields can be accessed.
Parameters:
- logger: The Omni logger instance (interface{})
- method: HTTP method (GET, POST, etc.)
- path: Request path
- headers: Request headers
- body: Request body
Example:
features.LogRequest(logger, "POST", "/api/login", headers, body)
func LogResponse ¶
LogResponse logs an API response with automatic redaction of sensitive data. It redacts sensitive headers and fields in the response body.
Note: This function provides the interface but the actual implementation should be in the omni package where private fields can be accessed.
Parameters:
- logger: The Omni logger instance (interface{})
- statusCode: HTTP status code
- headers: Response headers
- body: Response body
Example:
features.LogResponse(logger, 200, responseHeaders, responseBody)
func MatchesPath ¶
MatchesPath checks if a field path matches a pattern (supports wildcards)
func RecursiveRedact ¶
func RecursiveRedact(v interface{}, currentPath string, redactor *Redactor, fieldPathRules []FieldPathRule)
RecursiveRedact walks the JSON structure and redacts sensitive values. It recursively processes maps and arrays to find and redact sensitive fields. Also handles field path-based redaction.
Parameters:
- v: The value to process (can be map, slice, or other types)
- currentPath: The current JSON path (e.g., "user.profile")
- redactor: Custom redactor instance
- fieldPathRules: Field path rules for targeted redaction
func RecursiveRedactWithSkip ¶
func RecursiveRedactWithSkip(v interface{}, currentPath string, redactor *Redactor, fieldPathRules []FieldPathRule, skipFields map[string]bool)
RecursiveRedactWithSkip walks the JSON structure and redacts sensitive values, skipping specified fields. It recursively processes maps and arrays to find and redact sensitive fields. Also handles field path-based redaction.
Parameters:
- v: The value to process (can be map, slice, or other types)
- currentPath: The current JSON path (e.g., "user.profile")
- redactor: Custom redactor instance
- fieldPathRules: Field path rules for targeted redaction
- skipFields: Map of field names to skip (already redacted)
func RedactSensitive ¶
func RedactSensitive(input string, config *RedactionConfig, redactor *Redactor, fieldPathRules []FieldPathRule) string
RedactSensitive replaces sensitive information with [REDACTED]. It uses optimized redaction with configurable options and lazy JSON parsing.
Parameters:
- input: The string to redact
- config: Redaction configuration
- redactor: Custom redactor instance
- fieldPathRules: Field path rules for targeted redaction
Returns:
- string: The redacted string
func RedactSensitiveWithLevel ¶
func RedactSensitiveWithLevel(input string, level int, config *RedactionConfig, redactor *Redactor, fieldPathRules []FieldPathRule) string
RedactSensitiveWithLevel replaces sensitive information with level-aware redaction. It checks if redaction should be skipped for the given level.
Parameters:
- input: The string to redact
- level: The log level for this message
- config: Redaction configuration
- redactor: Custom redactor instance
- fieldPathRules: Field path rules for targeted redaction
Returns:
- string: The redacted string
func RegexRedact ¶
RegexRedact applies fallback regex-based redaction on raw text. Used when JSON parsing fails or for non-JSON content.
Parameters:
- input: The string to redact
- redactor: Custom redactor instance
Returns:
- string: The redacted string
func RemoveFieldPathRule ¶
func RemoveFieldPathRule(logger interface{}, path string)
RemoveFieldPathRule removes a field path rule.
Note: This function provides the interface but the actual implementation should be in the omni package where private fields can be accessed.
Parameters:
- logger: The Omni logger instance (interface{})
- path: The field path to remove
func SetRedaction ¶
SetRedaction sets custom redaction patterns for the logger. These patterns will be applied to all log messages to remove sensitive data.
Note: This function provides the interface but the actual implementation should be in the omni package where private fields can be accessed.
Parameters:
- logger: The Omni logger instance (interface{})
- patterns: Array of regex patterns to match sensitive data
- replace: The replacement string
Returns:
- error: If any pattern fails to compile
Example:
features.SetRedaction(logger, []string{
`password=\S+`, // Redact password parameters
`api_key:\s*"[^"]+"` // Redact API keys
}, "[REDACTED]")
func SetRedactionConfig ¶
func SetRedactionConfig(logger interface{}, config *RedactionConfig)
SetRedactionConfig sets the redaction configuration with advanced options.
Note: This function provides the interface but the actual implementation should be in the omni package where private fields can be accessed.
Parameters:
- logger: The Omni logger instance (interface{})
- config: RedactionConfig with various redaction behavior settings
Example:
features.SetRedactionConfig(logger, &features.RedactionConfig{
EnableBuiltInPatterns: true,
EnableFieldRedaction: true,
EnableDataPatterns: true,
SkipLevels: []int{0}, // Don't redact debug logs (level 0)
MaxCacheSize: 5000,
})
func ShouldRedactPath ¶
func ShouldRedactPath(path string, fieldPathRules []FieldPathRule) bool
ShouldRedactPath checks if a specific field path should be redacted
Types ¶
type AdaptiveSampler ¶
type AdaptiveSampler struct {
// contains filtered or unexported fields
}
AdaptiveSampler provides adaptive sampling functionality
func NewAdaptiveSampler ¶
func NewAdaptiveSampler(targetRate, minRate, maxRate float64) *AdaptiveSampler
NewAdaptiveSampler creates a new adaptive sampler
type AdaptiveWindow ¶
AdaptiveWindow tracks metrics for a time window
type BurstTracker ¶
type BurstTracker struct {
// contains filtered or unexported fields
}
BurstTracker tracks burst patterns
func NewBurstTracker ¶
func NewBurstTracker(window time.Duration, burstSize int) *BurstTracker
NewBurstTracker creates a new burst tracker
func (*BurstTracker) ShouldLog ¶
func (b *BurstTracker) ShouldLog() bool
ShouldLog determines if a message should be logged based on burst detection
type CompressibleLogger ¶
type CompressibleLogger interface {
Logger
// SetCompression enables/disables compression
SetCompression(compressionType int) error
// SetCompressMinAge sets minimum age before compression
SetCompressMinAge(age int)
// SetCompressWorkers sets number of compression workers
SetCompressWorkers(workers int)
}
CompressibleLogger interface for loggers that support compression
type CompressionConfig ¶
type CompressionConfig struct {
Type int // Compression type (types.CompressionNone, types.CompressionGzip)
MinAge int // Minimum number of rotations before compression
Workers int // Number of compression workers
Enabled bool // Whether compression is enabled
}
CompressionConfig holds compression configuration
type CompressionManager ¶
type CompressionManager struct {
// contains filtered or unexported fields
}
CompressionManager handles log file compression
func NewCompressionManager ¶
func NewCompressionManager() *CompressionManager
NewCompressionManager creates a new compression manager
func (*CompressionManager) CompressFileSync ¶
func (c *CompressionManager) CompressFileSync(path string) error
CompressFileSync compresses a file synchronously (blocking)
func (*CompressionManager) GetMinAge ¶
func (c *CompressionManager) GetMinAge() int
GetMinAge returns the minimum age for compression
func (*CompressionManager) GetStatus ¶
func (c *CompressionManager) GetStatus() CompressionStatus
GetStatus returns the current status of the compression manager
func (*CompressionManager) GetType ¶
func (c *CompressionManager) GetType() CompressionType
GetType returns the current compression type
func (*CompressionManager) QueueFile ¶
func (c *CompressionManager) QueueFile(path string)
QueueFile adds a file to the compression queue
func (*CompressionManager) SetCompression ¶
func (c *CompressionManager) SetCompression(compressionType CompressionType) error
SetCompression enables or disables compression for rotated log files
func (*CompressionManager) SetErrorHandler ¶
func (c *CompressionManager) SetErrorHandler(handler func(source, dest, msg string, err error))
SetErrorHandler sets the error handling function
func (*CompressionManager) SetMetricsHandler ¶
func (c *CompressionManager) SetMetricsHandler(handler func(string))
SetMetricsHandler sets the metrics tracking function
func (*CompressionManager) SetMinAge ¶
func (c *CompressionManager) SetMinAge(age int)
SetMinAge sets the minimum number of rotations before a log file is compressed
func (*CompressionManager) SetWorkers ¶
func (c *CompressionManager) SetWorkers(workers int)
SetWorkers sets the number of compression worker goroutines
func (*CompressionManager) Start ¶
func (c *CompressionManager) Start()
Start starts the compression manager
func (*CompressionManager) Stop ¶
func (c *CompressionManager) Stop()
Stop stops the compression manager
type CompressionStatus ¶
type CompressionStatus struct {
Type CompressionType `json:"type"`
MinAge int `json:"min_age"`
Workers int `json:"workers"`
IsRunning bool `json:"is_running"`
QueueLength int `json:"queue_length"`
QueueCapacity int `json:"queue_capacity"`
}
CompressionStatus represents the status of the compression manager
type CompressionType ¶
type CompressionType int
CompressionType defines the compression algorithm used for rotated log files.
const ( // CompressionNone disables compression CompressionNone CompressionType = iota // CompressionGzip enables gzip compression CompressionGzip )
func GetSupportedCompressionTypes ¶
func GetSupportedCompressionTypes() []CompressionType
GetSupportedTypes returns all supported compression types
func ParseCompressionType ¶
func ParseCompressionType(s string) (CompressionType, error)
ParseCompressionType parses a string into a CompressionType
type Compressor ¶
type Compressor interface {
// Compress compresses a file
Compress(src, dest string) error
// Type returns the compression type
Type() int
// Extension returns the file extension for compressed files
Extension() string
}
Compressor interface for log file compression
type ContextualRule ¶
type ContextualRule struct {
Name string
Condition func(level int, fields map[string]interface{}) bool
RedactFields []string
Replacement string
}
ContextualRule defines context-aware redaction rules
type FieldPathRule ¶
type FieldPathRule struct {
Path string // JSON path like "user.profile.ssn"
Replacement string // Custom replacement text for this path
}
FieldPathRule defines a rule for redacting specific field paths
func GetFieldPathRules ¶
func GetFieldPathRules(logger interface{}) []FieldPathRule
GetFieldPathRules returns all configured field path rules.
Note: This function provides the interface but the actual implementation should be in the omni package where private fields can be accessed.
Parameters:
- logger: The Omni logger instance (interface{})
Returns:
- []FieldPathRule: A copy of all field path rules
type FieldRedactionRule ¶
type FieldRedactionRule struct {
FieldPath string // JSONPath-like field path
Pattern string // Regex pattern to match
Replace string // Replacement string
}
FieldRedactionRule defines redaction rules for specific fields
type Filter ¶
type Filter interface {
// ShouldLog determines if a message should be logged
ShouldLog(level int, message string, fields map[string]interface{}) bool
// Name returns the filter name for identification
Name() string
}
Filter interface for log message filtering
type FilterCache ¶
type FilterCache struct {
// contains filtered or unexported fields
}
FilterCache provides caching for filter decisions
func (*FilterCache) Get ¶
func (c *FilterCache) Get(key string) (bool, bool)
Get retrieves a cached filter decision
func (*FilterCache) GetStats ¶
func (c *FilterCache) GetStats() (hits, misses, evictions uint64)
GetStats returns cache statistics
func (*FilterCache) Set ¶
func (c *FilterCache) Set(key string, decision bool)
Set stores a filter decision in cache
type FilterChain ¶
type FilterChain struct {
Name string
Mode ChainMode // AND, OR, XOR modes
Filters []NamedFilter
StopOnMatch bool // Stop evaluating after first match (for OR mode)
Inverted bool // Invert the final result
}
FilterChain represents a chain of filters with specific behavior
type FilterFunc ¶
FilterFunc is a function that determines if a log entry should be logged. It receives the log level, message, and structured fields. Returns true if the message should be logged, false to filter it out.
func CreateCompositeFilter ¶
func CreateCompositeFilter(filters ...FilterFunc) FilterFunc
CreateCompositeFilter creates a filter that combines multiple filters with AND logic
func CreateExcludeRegexFilter ¶
func CreateExcludeRegexFilter(pattern *regexp.Regexp) FilterFunc
CreateExcludeRegexFilter creates a filter that excludes entries matching a regex pattern. Messages that match the pattern will be filtered out (opposite of CreateRegexFilter).
func CreateFieldExistsFilter ¶
func CreateFieldExistsFilter(field string) FilterFunc
CreateFieldExistsFilter creates a filter that only logs entries containing a specific field.
func CreateFieldFilter ¶
func CreateFieldFilter(field string, values ...interface{}) FilterFunc
CreateFieldFilter creates a filter that only logs entries containing specific field values. The filter checks if the specified field exists and matches any of the provided values.
func CreateFieldNotExistsFilter ¶
func CreateFieldNotExistsFilter(field string) FilterFunc
CreateFieldNotExistsFilter creates a filter that only logs entries NOT containing a specific field.
func CreateFieldPrefixFilter ¶
func CreateFieldPrefixFilter(prefix string) FilterFunc
CreateFieldPrefixFilter creates a filter for fields with specific prefixes
func CreateFieldRangeFilter ¶
func CreateFieldRangeFilter(field string, min, max float64) FilterFunc
CreateFieldRangeFilter creates a filter for numeric field values within a range
func CreateLevelFieldFilter ¶
func CreateLevelFieldFilter(logLevel int, field string, value interface{}) FilterFunc
CreateLevelFieldFilter creates a filter that only logs entries with a specific level and field value. This allows fine-grained control over what gets logged based on both level and context.
func CreateLevelFilter ¶
func CreateLevelFilter(minLevel int) FilterFunc
CreateLevelFilter creates a filter that only logs messages at or above a certain level.
func CreateMultiFieldFilter ¶
func CreateMultiFieldFilter(fields ...string) FilterFunc
CreateMultiFieldFilter creates a filter that requires all specified fields to exist.
func CreateNotFilter ¶
func CreateNotFilter(filter FilterFunc) FilterFunc
CreateNotFilter creates a filter that inverts another filter's decision
func CreateOrFilter ¶
func CreateOrFilter(filters ...FilterFunc) FilterFunc
CreateOrFilter creates a filter that combines multiple filters with OR logic
func CreateRateLimitFilter ¶
func CreateRateLimitFilter(maxPerSecond float64) FilterFunc
CreateRateLimitFilter creates a filter that limits log frequency
func CreateRegexFilter ¶
func CreateRegexFilter(pattern *regexp.Regexp) FilterFunc
CreateRegexFilter creates a filter that only logs entries matching a regex pattern. Messages that don't match the pattern will be filtered out.
func CreateTimeWindowFilter ¶
func CreateTimeWindowFilter(startHour, endHour int) FilterFunc
CreateTimeWindowFilter creates a filter that only logs during specific time windows
type FilterManager ¶
type FilterManager struct {
// contains filtered or unexported fields
}
FilterManager handles log filtering
func NewFilterManager ¶
func NewFilterManager() *FilterManager
NewFilterManager creates a new filter manager
func (*FilterManager) AddFilter ¶
func (f *FilterManager) AddFilter(filter FilterFunc) error
AddFilter adds a filter function that determines whether a log entry should be logged. Filters are applied in the order they were added. A message is logged only if all filters return true.
func (*FilterManager) AddFilterChain ¶
func (f *FilterManager) AddFilterChain(chain *FilterChain) error
AddFilterChain adds a chain of filters with specific combination logic
func (*FilterManager) AddNamedFilter ¶
func (f *FilterManager) AddNamedFilter(name, description string, filter FilterFunc, priority int) error
AddNamedFilter adds a named filter with metadata
func (*FilterManager) ApplyFilters ¶
func (f *FilterManager) ApplyFilters(level int, message string, fields map[string]interface{}) bool
ApplyFilters checks if a message should be logged based on all filters. Returns true if all filters pass, false if any filter rejects the message.
func (*FilterManager) ClearFilters ¶
func (f *FilterManager) ClearFilters()
ClearFilters removes all filters. After calling this, all messages will be logged (subject to level and sampling).
func (*FilterManager) DisableCache ¶
func (f *FilterManager) DisableCache()
DisableCache disables filter decision caching
func (*FilterManager) DisableFilter ¶
func (f *FilterManager) DisableFilter(name string) error
DisableFilter disables a filter by name without removing it
func (*FilterManager) EnableCache ¶
func (f *FilterManager) EnableCache(maxSize int, ttl time.Duration)
EnableCache enables caching of filter decisions
func (*FilterManager) EnableFilter ¶
func (f *FilterManager) EnableFilter(name string) error
EnableFilter enables a filter by name
func (*FilterManager) Get ¶
func (f *FilterManager) Get(name string) (*NamedFilter, bool)
Get returns a filter by name
func (*FilterManager) GetFilterCount ¶
func (f *FilterManager) GetFilterCount() int
GetFilterCount returns the number of active filters
func (*FilterManager) GetMetrics ¶
func (f *FilterManager) GetMetrics() FilterMetrics
GetMetrics returns current filter metrics
func (*FilterManager) GetStatus ¶
func (f *FilterManager) GetStatus() FilterStatus
GetStatus returns the current status of the filter manager
func (*FilterManager) ListChains ¶
func (f *FilterManager) ListChains() map[string]*FilterChain
ListChains returns all filter chains
func (*FilterManager) RemoveFilter ¶
func (f *FilterManager) RemoveFilter(name string) error
RemoveFilter removes a filter by name
func (*FilterManager) RemoveFilterChain ¶
func (f *FilterManager) RemoveFilterChain(name string) error
RemoveFilterChain removes a filter chain by name
func (*FilterManager) ResetMetrics ¶
func (f *FilterManager) ResetMetrics()
ResetMetrics resets all filter metrics
func (*FilterManager) SetErrorHandler ¶
func (f *FilterManager) SetErrorHandler(handler func(source, dest, msg string, err error))
SetErrorHandler sets the error handling function
func (*FilterManager) SetMetricsHandler ¶
func (f *FilterManager) SetMetricsHandler(handler func(string))
SetMetricsHandler sets the metrics tracking function
type FilterMetrics ¶
type FilterMetrics struct {
TotalChecks uint64
TotalPassed uint64
TotalFiltered uint64
FilterHits map[string]uint64
ChainHits map[string]uint64
CacheHits uint64
CacheMisses uint64
ProcessingTimeNs int64
LastUpdate time.Time
}
FilterMetrics tracks filtering statistics
type FilterStatus ¶
type FilterStatus struct {
FilterCount int `json:"filter_count"`
ChainCount int `json:"chain_count"`
ActiveFilters int `json:"active_filters"`
DisabledFilters int `json:"disabled_filters"`
CacheEnabled bool `json:"cache_enabled"`
CacheSize int `json:"cache_size,omitempty"`
CacheMaxSize int `json:"cache_max_size,omitempty"`
CacheTTL time.Duration `json:"cache_ttl,omitempty"`
}
FilterStatus represents the current status of filtering
type FilterableLogger ¶
type FilterableLogger interface {
Logger
// AddFilter adds a filter function
AddFilter(filter types.FilterFunc) error
// RemoveFilter removes a filter function
RemoveFilter(filter types.FilterFunc) error
// ClearFilters removes all filters
ClearFilters()
}
FilterableLogger interface for loggers that support filtering
type FullFeaturedLogger ¶
type FullFeaturedLogger interface {
StructuredLogger
FilterableLogger
SamplableLogger
RotatableLogger
CompressibleLogger
RecoverableLogger
RedactableLogger
MetricsLogger
}
FullFeaturedLogger interface that combines all logger capabilities
type LevelFilter ¶
LevelFilter filters based on log levels
type Logger ¶
type Logger interface {
// Basic logging methods
Debug(args ...interface{})
Info(args ...interface{})
Warn(args ...interface{})
Error(args ...interface{})
// Formatted logging methods
Debugf(format string, args ...interface{})
Infof(format string, args ...interface{})
Warnf(format string, args ...interface{})
Errorf(format string, args ...interface{})
// Close closes the logger
Close() error
}
Logger interface that defines the basic logging operations
type MetricsLogger ¶
type MetricsLogger interface {
Logger
// GetMetrics returns logger metrics
GetMetrics() map[string]interface{}
// ResetMetrics resets all metrics
ResetMetrics()
}
MetricsLogger interface for loggers that support metrics
type NamedFilter ¶
type NamedFilter struct {
Name string
Description string
Filter FilterFunc
Priority int // Higher priority filters are evaluated first
Enabled bool // Can be toggled without removing
Tags []string
}
NamedFilter represents a filter with metadata
type PatternSamplingRule ¶
type PatternSamplingRule struct {
Pattern string
Rate float64
Priority int // Higher priority rules override lower ones
Description string
MatchFields bool // Whether to match against fields as well
}
PatternSamplingRule defines sampling rules based on message patterns
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter implements token bucket algorithm
func NewRateLimiter ¶
func NewRateLimiter(maxPerSecond float64) *RateLimiter
NewRateLimiter creates a new rate limiter
func (*RateLimiter) Allow ¶
func (r *RateLimiter) Allow() bool
Allow checks if a message is allowed based on rate limiting
type RecoverableLogger ¶
type RecoverableLogger interface {
Logger
// SetRecoveryConfig sets recovery configuration (defined in recovery.go)
SetRecoveryConfig(config interface{})
// RecoverFromError attempts to recover from an error
RecoverFromError(err error, msg types.LogMessage, dest *types.Destination)
}
RecoverableLogger interface for loggers that support error recovery
type Recovery ¶
type Recovery interface {
// Recover attempts to recover from an error
Recover(err error) error
// IsRecoverable determines if an error is recoverable
IsRecoverable(err error) bool
// GetFallbackOptions returns fallback options
GetFallbackOptions() []string
}
Recovery interface for error recovery
type RecoveryConfig ¶
type RecoveryConfig struct {
// Maximum retry attempts
MaxRetries int
// Delay between retries
RetryDelay time.Duration
// Exponential backoff multiplier
BackoffMultiplier float64
// Maximum retry delay
MaxRetryDelay time.Duration
// Fallback destination
FallbackPath string
// Buffer size for temporary storage
BufferSize int
// Recovery strategy
Strategy RecoveryStrategy
}
RecoveryConfig configures error recovery behavior. It provides comprehensive options for handling logging failures gracefully.
func DefaultRecoveryConfig ¶
func DefaultRecoveryConfig() *RecoveryConfig
DefaultRecoveryConfig returns default recovery configuration. These defaults provide a reasonable balance between reliability and performance.
Returns:
- *RecoveryConfig: Configuration with sensible defaults
type RecoveryManager ¶
type RecoveryManager struct {
// contains filtered or unexported fields
}
RecoveryManager handles error recovery for the logger. It implements various strategies to ensure log messages are not lost even when the primary logging destination fails.
func NewRecoveryManager ¶
func NewRecoveryManager(config *RecoveryConfig) *RecoveryManager
NewRecoveryManager creates a new recovery manager. If config is nil, default configuration is used.
Parameters:
- config: Recovery configuration (can be nil)
Returns:
- *RecoveryManager: A new recovery manager instance
func (*RecoveryManager) Close ¶
func (rm *RecoveryManager) Close() error
Close closes the recovery manager. This ensures any open fallback files are properly closed.
Returns:
- error: Close error if fallback file fails to close
func (*RecoveryManager) FlushBuffer ¶
func (rm *RecoveryManager) FlushBuffer(processFunc func(message interface{}) error) error
FlushBuffer processes all buffered messages.
func (*RecoveryManager) GetBufferSize ¶
func (rm *RecoveryManager) GetBufferSize() int
GetBufferSize returns the current buffer size.
func (*RecoveryManager) GetConfig ¶
func (rm *RecoveryManager) GetConfig() *RecoveryConfig
GetConfig returns the recovery configuration.
func (*RecoveryManager) GetRetryCount ¶
func (rm *RecoveryManager) GetRetryCount(destName string) int
GetRetryCount returns the current retry count for a destination.
func (*RecoveryManager) HandleError ¶
func (rm *RecoveryManager) HandleError(err error, message interface{}, destName string, writeFunc func() error)
HandleError handles an error with the configured recovery strategy.
func (*RecoveryManager) ResetRetryCount ¶
func (rm *RecoveryManager) ResetRetryCount(destName string)
ResetRetryCount resets the retry count for a destination.
func (*RecoveryManager) SetErrorHandler ¶
func (rm *RecoveryManager) SetErrorHandler(handler func(source, dest, msg string, err error))
SetErrorHandler sets the error handling function
func (*RecoveryManager) SetMetricsHandler ¶
func (rm *RecoveryManager) SetMetricsHandler(handler func(event string))
SetMetricsHandler sets the metrics tracking function
func (*RecoveryManager) UpdateConfig ¶
func (rm *RecoveryManager) UpdateConfig(config *RecoveryConfig)
UpdateConfig updates the recovery configuration.
type RecoveryStrategy ¶
type RecoveryStrategy int
RecoveryStrategy defines how to handle errors. Different strategies provide flexibility in error handling based on the situation.
const ( // RecoveryRetry attempts to retry the operation with exponential backoff RecoveryRetry RecoveryStrategy = iota // RecoveryFallback falls back to an alternative destination (e.g., local file) RecoveryFallback // RecoveryDrop drops the message without retrying RecoveryDrop // RecoveryBuffer buffers messages temporarily for later processing RecoveryBuffer )
type RedactableLogger ¶
type RedactableLogger interface {
Logger
// SetRedaction sets redaction patterns
SetRedaction(patterns []string, replace string) error
// SetRedactionConfig sets advanced redaction configuration (defined in redaction.go)
SetRedactionConfig(config interface{})
// EnableRedactionForLevel enables/disables redaction for a specific level
EnableRedactionForLevel(level int, enable bool)
}
RedactableLogger interface for loggers that support redaction
type RedactionCache ¶
type RedactionCache struct {
// contains filtered or unexported fields
}
RedactionCache provides caching for redaction operations
type RedactionConfig ¶
type RedactionConfig struct {
EnableBuiltInPatterns bool // Whether to apply built-in data patterns (SSN, credit cards, etc.)
EnableFieldRedaction bool // Whether to apply JSON field redaction
EnableDataPatterns bool // Whether to apply data pattern redaction in content
MaxCacheSize int // Maximum size of redaction cache
SkipLevels []int // Log levels to skip redaction for (e.g., DEBUG)
FieldPaths []string // Specific field paths to redact (e.g., "user.profile.ssn")
}
RedactionConfig holds configuration for redaction behavior
func GetRedactionConfig ¶
func GetRedactionConfig(logger interface{}) *RedactionConfig
GetRedactionConfig returns the current redaction configuration.
Note: This function provides the interface but the actual implementation should be in the omni package where private fields can be accessed.
Parameters:
- logger: The Omni logger instance (interface{})
Returns:
- *RedactionConfig: The current redaction configuration or nil if not set
type RedactionManager ¶
type RedactionManager struct {
// contains filtered or unexported fields
}
RedactionManager provides comprehensive redaction management
func NewRedactionManager ¶
func NewRedactionManager() *RedactionManager
NewRedactionManager creates a new redaction manager
func (*RedactionManager) AddContextualRule ¶
func (rm *RedactionManager) AddContextualRule(rule ContextualRule)
AddContextualRule adds a context-aware redaction rule
func (*RedactionManager) AddFieldPathRule ¶
func (rm *RedactionManager) AddFieldPathRule(rule FieldPathRule)
AddFieldPathRule adds a field path rule
func (*RedactionManager) GetMetrics ¶
func (rm *RedactionManager) GetMetrics() RedactionMetrics
GetMetrics returns current metrics
func (*RedactionManager) RedactMessage ¶
func (rm *RedactionManager) RedactMessage(level int, message string, fields map[string]interface{}) (string, map[string]interface{})
RedactMessage redacts a log message with full context
func (*RedactionManager) RemoveFieldPathRule ¶
func (rm *RedactionManager) RemoveFieldPathRule(path string)
RemoveFieldPathRule removes a field path rule
func (*RedactionManager) SetConfig ¶
func (rm *RedactionManager) SetConfig(config *RedactionConfig)
SetConfig sets the redaction configuration
func (*RedactionManager) SetCustomRedactor ¶
func (rm *RedactionManager) SetCustomRedactor(redactor *Redactor)
SetCustomRedactor sets a custom redactor
func (*RedactionManager) SetErrorHandler ¶
func (rm *RedactionManager) SetErrorHandler(handler func(source, dest, msg string, err error))
SetErrorHandler sets the error handling function
func (*RedactionManager) SetMetricsHandler ¶
func (rm *RedactionManager) SetMetricsHandler(handler func(string))
SetMetricsHandler sets the metrics tracking function
type RedactionMetrics ¶
type RedactionMetrics struct {
TotalProcessed uint64
TotalRedacted uint64
FieldsRedacted map[string]uint64
PatternsMatched map[string]uint64
ProcessingTimeNs int64
CacheHits uint64
CacheMisses uint64
LastUpdate time.Time
}
RedactionMetrics tracks redaction statistics
type RedactionMode ¶
type RedactionMode int
RedactionMode defines how redaction is performed
const ( // RedactionModeReplace replaces sensitive data with placeholder RedactionModeReplace RedactionMode = iota // RedactionModeHash replaces with consistent hash RedactionModeHash // RedactionModeMask partially masks the value RedactionModeMask // RedactionModeRemove removes the field entirely RedactionModeRemove )
type Redactor ¶
type Redactor struct {
// contains filtered or unexported fields
}
Redactor handles pattern-based redaction with performance optimizations. It applies a set of regex patterns to replace sensitive data.
func CreateAPIKeyRedactor ¶
func CreateAPIKeyRedactor() *Redactor
CreateAPIKeyRedactor creates a redactor for common API key formats
func CreateCreditCardRedactor ¶
func CreateCreditCardRedactor() *Redactor
CreateCreditCardRedactor creates a redactor for credit card numbers
func CreateEmailRedactor ¶
func CreateEmailRedactor() *Redactor
CreateEmailRedactor creates a redactor for email addresses
func CreateSSNRedactor ¶
func CreateSSNRedactor() *Redactor
CreateSSNRedactor creates a redactor for SSN patterns
func NewRedactor ¶
NewRedactor creates a new redactor with custom patterns and performance optimizations.
Parameters:
- patterns: Array of regex patterns to match sensitive data
- replace: The replacement string (e.g., "[REDACTED]")
Returns:
- *Redactor: The configured redactor
- error: If any pattern fails to compile
Example:
redactor, err := features.NewRedactor([]string{
`\b\d{3}-\d{2}-\d{4}\b`, // SSN pattern
`\b\d{16}\b`, // Credit card pattern
}, "[REDACTED]")
func (*Redactor) ClearCache ¶
func (r *Redactor) ClearCache()
ClearCache clears the redaction cache to free memory
type RedactorInterface ¶
type RedactorInterface interface {
// Redact redacts sensitive data from a message
Redact(message string) string
// RedactFields redacts sensitive data from structured fields
RedactFields(fields map[string]interface{}) map[string]interface{}
// AddPattern adds a redaction pattern
AddPattern(pattern string)
// RemovePattern removes a redaction pattern
RemovePattern(pattern string)
}
RedactorInterface interface for sensitive data redaction
type RegexFilter ¶
type RegexFilter struct {
Pattern *regexp.Regexp
Include bool // true to include matches, false to exclude
}
RegexFilter filters based on regular expression patterns
type RotatableLogger ¶
type RotatableLogger interface {
Logger
// SetMaxSize sets maximum file size before rotation
SetMaxSize(size int64)
// SetMaxFiles sets maximum number of files to keep
SetMaxFiles(files int)
// SetMaxAge sets maximum age for log files
SetMaxAge(age time.Duration) error
// Rotate manually triggers rotation
Rotate() error
}
RotatableLogger interface for loggers that support rotation
type RotatedFileInfo ¶
type RotatedFileInfo struct {
Path string `json:"path"`
Name string `json:"name"`
Size int64 `json:"size"`
RotationTime time.Time `json:"rotation_time"`
IsCompressed bool `json:"is_compressed"`
}
RotatedFileInfo contains information about a rotated log file
type RotationConfig ¶
type RotationConfig struct {
MaxSize int64 // Maximum file size before rotation
MaxFiles int // Maximum number of files to keep
MaxAge time.Duration // Maximum age of files
KeepOriginal bool // Whether to keep the original file
}
RotationConfig holds rotation configuration
type RotationManager ¶
type RotationManager struct {
// contains filtered or unexported fields
}
RotationManager handles log file rotation and cleanup
func NewRotationManager ¶
func NewRotationManager() *RotationManager
NewRotationManager creates a new rotation manager
func (*RotationManager) AddLogPath ¶
func (r *RotationManager) AddLogPath(path string)
AddLogPath adds a log path to be managed by this rotation manager
func (*RotationManager) CleanupOldFiles ¶
func (r *RotationManager) CleanupOldFiles(logPath string) error
CleanupOldFiles removes old rotated files based on maxFiles count.
func (*RotationManager) CleanupOldLogs ¶
func (r *RotationManager) CleanupOldLogs(logPath string) error
CleanupOldLogs removes log files older than maxAge.
func (*RotationManager) GetCleanupInterval ¶
func (r *RotationManager) GetCleanupInterval() time.Duration
GetCleanupInterval returns the cleanup interval
func (*RotationManager) GetMaxAge ¶
func (r *RotationManager) GetMaxAge() time.Duration
GetMaxAge returns the maximum age for log files
func (*RotationManager) GetMaxFiles ¶
func (r *RotationManager) GetMaxFiles() int
GetMaxFiles returns the maximum number of files to keep
func (*RotationManager) GetRotatedFiles ¶
func (r *RotationManager) GetRotatedFiles(logPath string) ([]RotatedFileInfo, error)
GetRotatedFiles returns a list of rotated files for the given log path
func (*RotationManager) GetStatus ¶
func (r *RotationManager) GetStatus() RotationStatus
GetStatus returns the current status of the rotation manager
func (*RotationManager) IsRunning ¶
func (r *RotationManager) IsRunning() bool
IsRunning returns whether the cleanup routine is running
func (*RotationManager) RemoveLogPath ¶
func (r *RotationManager) RemoveLogPath(path string)
RemoveLogPath removes a log path from management
func (*RotationManager) RotateFile ¶
RotateFile rotates a log file by renaming it with a timestamp suffix
func (*RotationManager) RunCleanup ¶
func (r *RotationManager) RunCleanup(logPath string) error
RunCleanup immediately runs the cleanup process for old log files
func (*RotationManager) SetCleanupInterval ¶
func (r *RotationManager) SetCleanupInterval(interval time.Duration)
SetCleanupInterval sets how often to check for and remove old log files
func (*RotationManager) SetCompressionCallback ¶
func (r *RotationManager) SetCompressionCallback(callback func(path string))
SetCompressionCallback sets the callback function for queuing files for compression
func (*RotationManager) SetErrorHandler ¶
func (r *RotationManager) SetErrorHandler(handler func(source, dest, msg string, err error))
SetErrorHandler sets the error handling function
func (*RotationManager) SetMaxAge ¶
func (r *RotationManager) SetMaxAge(duration time.Duration) error
SetMaxAge sets the maximum age for log files
func (*RotationManager) SetMaxFiles ¶
func (r *RotationManager) SetMaxFiles(count int)
SetMaxFiles sets the maximum number of rotated files to keep
func (*RotationManager) SetMetricsHandler ¶
func (r *RotationManager) SetMetricsHandler(handler func(string))
SetMetricsHandler sets the metrics tracking function
type RotationStatus ¶
type RotationStatus struct {
MaxAge time.Duration `json:"max_age"`
MaxFiles int `json:"max_files"`
CleanupInterval time.Duration `json:"cleanup_interval"`
IsRunning bool `json:"is_running"`
}
RotationStatus represents the status of the rotation manager
type Rotator ¶
type Rotator interface {
// Rotate rotates the log file
Rotate(currentPath string) error
// ShouldRotate determines if rotation is needed
ShouldRotate(size int64, age time.Duration) bool
// GetRotatedFilename generates a rotated filename
GetRotatedFilename(basePath string, index int) string
}
Rotator interface for log file rotation
type SamplableLogger ¶
type SamplableLogger interface {
Logger
// SetSampling configures sampling
SetSampling(strategy int, rate float64) error
// GetSamplingRate returns current sampling rate
GetSamplingRate() float64
}
SamplableLogger interface for loggers that support sampling
type Sampler ¶
type Sampler interface {
// ShouldSample determines if a message should be sampled
ShouldSample(level int, message string, fields map[string]interface{}) bool
// Rate returns the current sampling rate
Rate() float64
// SetRate sets the sampling rate
SetRate(rate float64)
}
Sampler interface for log sampling
type SamplingConfig ¶
type SamplingConfig struct {
Strategy int // Sampling strategy (types.SamplingNone, types.SamplingRandom, etc.)
Rate float64 // Sampling rate (0.0-1.0)
KeyFunc func(int, string, map[string]interface{}) string // Key function for consistent sampling
}
SamplingConfig holds sampling configuration
type SamplingManager ¶
type SamplingManager struct {
// contains filtered or unexported fields
}
SamplingManager handles log sampling to reduce volume
func NewSamplingManager ¶
func NewSamplingManager() *SamplingManager
NewSamplingManager creates a new sampling manager
func (*SamplingManager) ExportMetrics ¶
func (s *SamplingManager) ExportMetrics() SamplingMetricsExport
ExportMetrics exports detailed metrics for analysis
func (*SamplingManager) GetMetrics ¶
func (s *SamplingManager) GetMetrics() SamplingMetrics
GetMetrics returns current sampling metrics
func (*SamplingManager) GetRate ¶
func (s *SamplingManager) GetRate() float64
GetRate returns the current sampling rate
func (*SamplingManager) GetStatus ¶
func (s *SamplingManager) GetStatus() SamplingStatus
GetStatus returns the current status of the sampling manager
func (*SamplingManager) GetStrategy ¶
func (s *SamplingManager) GetStrategy() SamplingStrategy
GetStrategy returns the current sampling strategy
func (*SamplingManager) Reset ¶
func (s *SamplingManager) Reset()
Reset resets the sampling manager to default state
func (*SamplingManager) SetAdaptiveConfig ¶
func (s *SamplingManager) SetAdaptiveConfig(targetRate, minRate, maxRate float64, windowSize time.Duration)
SetAdaptiveConfig configures adaptive sampling parameters
func (*SamplingManager) SetBurstConfig ¶
func (s *SamplingManager) SetBurstConfig(window time.Duration, burstSize int)
SetBurstConfig sets burst sampling configuration
func (*SamplingManager) SetErrorHandler ¶
func (s *SamplingManager) SetErrorHandler(handler func(source, dest, msg string, err error))
SetErrorHandler sets the error handling function
func (*SamplingManager) SetKeyFunc ¶
func (s *SamplingManager) SetKeyFunc(keyFunc func(level int, message string, fields map[string]interface{}) string)
SetKeyFunc sets the function used to generate the key for consistent sampling
func (*SamplingManager) SetLevelSampling ¶
func (s *SamplingManager) SetLevelSampling(levelRates map[int]float64)
SetLevelSampling sets sampling rates for specific log levels
func (*SamplingManager) SetMetricsHandler ¶
func (s *SamplingManager) SetMetricsHandler(handler func(string))
SetMetricsHandler sets the metrics tracking function
func (*SamplingManager) SetPatternRules ¶
func (s *SamplingManager) SetPatternRules(rules []PatternSamplingRule) error
SetPatternRules sets pattern-based sampling rules
func (*SamplingManager) SetStrategy ¶
func (s *SamplingManager) SetStrategy(strategy SamplingStrategy, rate float64) error
SetStrategy sets the sampling strategy and rate
type SamplingMetrics ¶
type SamplingMetrics struct {
TotalMessages uint64
SampledMessages uint64
DroppedMessages uint64
CurrentRate float64
EffectiveRate float64 // Actual sampling rate based on decisions
StrategyHits map[string]uint64
LevelHits map[int]uint64
PatternHits map[string]uint64
LastUpdate time.Time
}
SamplingMetrics tracks sampling statistics
type SamplingMetricsExport ¶
type SamplingMetricsExport struct {
TotalMessages uint64 `json:"total_messages"`
SampledMessages uint64 `json:"sampled_messages"`
DroppedMessages uint64 `json:"dropped_messages"`
CurrentRate float64 `json:"current_rate"`
EffectiveRate float64 `json:"effective_rate"`
LastUpdate time.Time `json:"last_update"`
Strategies map[string]uint64 `json:"strategies"`
Levels map[string]uint64 `json:"levels"`
Patterns map[string]uint64 `json:"patterns"`
}
SamplingMetricsExport represents exportable metrics
type SamplingStatus ¶
type SamplingStatus struct {
Strategy SamplingStrategy `json:"strategy"`
Rate float64 `json:"rate"`
IsActive bool `json:"is_active"`
LevelRates map[int]float64 `json:"level_rates,omitempty"`
PatternRules []PatternSamplingRule `json:"pattern_rules,omitempty"`
AdaptiveRate float64 `json:"adaptive_rate,omitempty"`
RateLimitTokens float64 `json:"rate_limit_tokens,omitempty"`
}
SamplingStatus represents the current status of sampling
type SamplingStrategy ¶
type SamplingStrategy int
SamplingStrategy defines how log sampling is performed to reduce log volume.
const ( // SamplingNone disables sampling - all messages are logged SamplingNone SamplingStrategy = iota // SamplingRandom randomly samples messages based on probability SamplingRandom // SamplingInterval logs every Nth message SamplingInterval // SamplingConsistent uses hash-based sampling for consistent decisions SamplingConsistent // SamplingAdaptive adjusts sampling rate based on traffic patterns SamplingAdaptive // SamplingRateLimited enforces a max messages per second limit SamplingRateLimited // SamplingBurst allows burst of messages then reduces rate SamplingBurst )
type StructuredLogger ¶
type StructuredLogger interface {
Logger
// WithField adds a single field
WithField(key string, value interface{}) StructuredLogger
// WithFields adds multiple fields
WithFields(fields map[string]interface{}) StructuredLogger
}
StructuredLogger interface for structured logging with fields