Documentation
¶
Overview ¶
Package logging provides a unified logging interface
Package logging provides a unified logging interface ¶
Package logging provides a unified logging interface
Index ¶
- Constants
- func CustomField(key string, value any, sanitizer func(any) string) zap.Field
- func MaskedField(key, value, mask string) zap.Field
- func ObjectField(key string, obj any) zap.Field
- func RequestID(key, value string) zap.Field
- func SafeString(key, value string) zap.Field
- func Sanitized(key, value string) zap.Field
- func SensitiveField(key string, value any) zap.Field
- func TruncatedField(key, value string, maxLength int) zap.Field
- type Factory
- type FactoryConfig
- type Field
- func Bool(key string, value bool) Field
- func Error(key string, err error) Field
- func Float(key string, value float64) Field
- func Int(key string, value int) Field
- func Int64(key string, value int64) Field
- func Object(key string, obj any) Field
- func Path(key, value string) Field
- func Sensitive(key string, value any) Field
- func String(key, value string) Field
- func UUID(key, value string) Field
- func UserAgent(key, value string) Field
- type FieldType
- type LogLevel
- type Logger
- type Sanitizer
- type SensitiveObject
Constants ¶
const ( // LogEncodingConsole represents console encoding for logs LogEncodingConsole = "console" // LogEncodingJSON represents JSON encoding for logs LogEncodingJSON = "json" // EnvironmentDevelopment represents the development environment EnvironmentDevelopment = "development" // MaxPartsLength represents the maximum number of parts in a log message MaxPartsLength = 2 // FieldPairSize represents the number of elements in a key-value pair FieldPairSize = 2 // MaxStringLength represents the maximum length for string fields MaxStringLength = 1000 // MaxPathLength represents the maximum length for path fields MaxPathLength = 500 // MaxUserAgentLength represents the maximum length for user agent fields MaxUserAgentLength = 1000 // UUIDLength represents the standard UUID length UUIDLength = 36 // UUIDParts represents the number of parts in a UUID UUIDParts = 5 // UUIDMinMaskLen represents the minimum length for UUID masking UUIDMinMaskLen = 8 // UUIDMaskPrefixLen represents the prefix length for UUID masking UUIDMaskPrefixLen = 4 // UUIDMaskSuffixLen represents the suffix length for UUID masking UUIDMaskSuffixLen = 4 )
Variables ¶
This section is empty.
Functions ¶
func CustomField ¶ added in v0.1.5
CustomField creates a field with custom sanitization logic
func MaskedField ¶ added in v0.1.5
MaskedField creates a field with custom masking applied to the value
func ObjectField ¶ added in v0.1.5
ObjectField creates a field with sanitized object data
func SafeString ¶ added in v0.1.5
SafeString creates a field with a safe string value (no sanitization)
func SensitiveField ¶ added in v0.1.5
SensitiveField creates a field that automatically masks sensitive data
Types ¶
type Factory ¶
type Factory struct {
LogLevel string
// contains filtered or unexported fields
}
Factory creates loggers based on configuration
func NewFactory ¶
func NewFactory(cfg *FactoryConfig, sanitizer sanitization.ServiceInterface) (*Factory, error)
NewFactory creates a new logger factory with the given configuration
func (*Factory) CreateLogger ¶
CreateLogger creates a new logger instance with the application name.
type FactoryConfig ¶ added in v0.1.5
type FactoryConfig struct {
AppName string
Version string
Environment string
LogLevel string
OutputPaths []string
ErrorOutputPaths []string
Fields map[string]any
}
FactoryConfig holds configuration for logger factory
func (*FactoryConfig) Validate ¶ added in v0.1.5
func (cfg *FactoryConfig) Validate() error
Validate validates the factory configuration
type Field ¶ added in v0.1.5
Field represents a structured log field with type information
func (Field) ToZapField ¶ added in v0.1.5
ToZapField converts a Field to a zap.Field
type FieldType ¶ added in v0.1.5
type FieldType int
FieldType represents the type of a field
const ( StringFieldType FieldType = iota IntFieldType FloatFieldType BoolFieldType ErrorFieldType ObjectFieldType UUIDFieldType PathFieldType UserAgentFieldType SensitiveFieldType // InvalidPathMessage is the message returned for invalid paths InvalidPathMessage = "[invalid path]" // UUIDDashCount is the number of dashes in a standard UUID UUIDDashCount = 4 )
type LogLevel ¶ added in v0.1.5
type LogLevel string
LogLevel represents the severity of a log message
const ( // LogLevelDebug represents debug level logging LogLevelDebug LogLevel = "debug" // LogLevelInfo represents info level logging LogLevelInfo LogLevel = "info" // LogLevelWarn represents warning level logging LogLevelWarn LogLevel = "warn" // LogLevelError represents error level logging LogLevelError LogLevel = "error" // LogLevelFatal represents fatal level logging LogLevelFatal LogLevel = "fatal" )
type Logger ¶
type Logger interface {
Debug(msg string, fields ...any)
Info(msg string, fields ...any)
Warn(msg string, fields ...any)
Error(msg string, fields ...any)
Fatal(msg string, fields ...any)
With(fields ...any) Logger
WithComponent(component string) Logger
WithOperation(operation string) Logger
WithRequestID(requestID string) Logger
WithUserID(userID string) Logger
WithError(err error) Logger
WithFields(fields map[string]any) Logger
// New Field-based API methods
WithFieldsStructured(fields ...Field) Logger
DebugWithFields(msg string, fields ...Field)
InfoWithFields(msg string, fields ...Field)
WarnWithFields(msg string, fields ...Field)
ErrorWithFields(msg string, fields ...Field)
FatalWithFields(msg string, fields ...Field)
SanitizeField(key string, value any) string
}
Logger interface defines the logging contract
type Sanitizer ¶ added in v0.1.5
type Sanitizer struct {
// contains filtered or unexported fields
}
Sanitizer provides simplified field sanitization
func NewSanitizer ¶ added in v0.1.5
func NewSanitizer() *Sanitizer
NewSanitizer creates a new sanitizer instance
func (*Sanitizer) ClearCache ¶ added in v0.1.5
func (s *Sanitizer) ClearCache()
ClearCache clears the sanitization cache
func (*Sanitizer) GetCacheSize ¶ added in v0.1.5
GetCacheSize returns the current cache size
type SensitiveObject ¶ added in v0.1.5
type SensitiveObject struct {
// contains filtered or unexported fields
}
SensitiveObject creates a custom field that implements zapcore.ObjectMarshaler for complex objects that need sensitive data masking
func NewSensitiveObject ¶ added in v0.1.5
func NewSensitiveObject(key string, value any) SensitiveObject
NewSensitiveObject creates a new sensitive object field
func (SensitiveObject) Field ¶ added in v0.1.5
func (s SensitiveObject) Field() zap.Field
Field returns the SensitiveObject as a zap.Field
func (SensitiveObject) MarshalLogObject ¶ added in v0.1.5
func (s SensitiveObject) MarshalLogObject(enc zapcore.ObjectEncoder) error
MarshalLogObject implements zapcore.ObjectMarshaler