Documentation
¶
Overview ¶
Package core provides the fundamental interfaces and types for mtlog.
Index ¶
- func AddTyped[T any](pb *PropertyBag, name string, value T)
- func GetTyped[T any](pb *PropertyBag, name string) (T, bool)
- type Destructurer
- type LogEvent
- type LogEventEnricher
- type LogEventFilter
- type LogEventLevel
- type LogEventProperty
- type LogEventPropertyFactory
- type LogEventSink
- type LogValue
- type Logger
- type PropertyBag
- type PropertyValue
- type SimpleSink
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddTyped ¶
func AddTyped[T any](pb *PropertyBag, name string, value T)
AddTyped adds a typed property to the bag
Types ¶
type Destructurer ¶
type Destructurer interface {
// TryDestructure attempts to destructure a value into a log event property.
// Returns the property and true if successful, nil and false otherwise.
TryDestructure(value interface{}, propertyFactory LogEventPropertyFactory) (*LogEventProperty, bool)
}
Destructurer converts complex types to log-appropriate representations.
type LogEvent ¶
type LogEvent struct {
// Timestamp is when the event occurred.
Timestamp time.Time
// Level is the severity of the event.
Level LogEventLevel
// MessageTemplate is the original message template with placeholders.
MessageTemplate string
// Properties contains the event's properties extracted from the template.
Properties map[string]interface{}
// Exception associated with the event, if any.
Exception error
}
LogEvent represents a single log event with all its properties.
func (*LogEvent) AddProperty ¶
AddProperty adds or overwrites a property in the event.
func (*LogEvent) AddPropertyIfAbsent ¶
func (e *LogEvent) AddPropertyIfAbsent(property *LogEventProperty)
AddPropertyIfAbsent adds a property to the event if it doesn't already exist.
type LogEventEnricher ¶
type LogEventEnricher interface {
// Enrich adds properties to the provided log event.
Enrich(event *LogEvent, propertyFactory LogEventPropertyFactory)
}
LogEventEnricher adds contextual properties to log events.
type LogEventFilter ¶
type LogEventFilter interface {
// IsEnabled returns true if the event should be logged.
IsEnabled(event *LogEvent) bool
}
LogEventFilter determines which events proceed through the pipeline.
type LogEventLevel ¶
type LogEventLevel int
LogEventLevel specifies the severity of a log event.
const ( // VerboseLevel is the most detailed logging level. VerboseLevel LogEventLevel = iota // DebugLevel is for debugging information. DebugLevel // InformationLevel is for informational messages. InformationLevel // WarningLevel is for warnings. WarningLevel // ErrorLevel is for errors. ErrorLevel // FatalLevel is for fatal errors. FatalLevel )
type LogEventProperty ¶
type LogEventProperty struct {
// Name is the property name.
Name string
// Value is the property value.
Value interface{}
}
LogEventProperty represents a single property of a log event.
type LogEventPropertyFactory ¶
type LogEventPropertyFactory interface {
// CreateProperty creates a new log event property.
CreateProperty(name string, value interface{}) *LogEventProperty
}
LogEventPropertyFactory creates log event properties.
type LogEventSink ¶
type LogEventSink interface {
// Emit writes the log event to the sink's destination.
Emit(event *LogEvent)
// Close releases any resources held by the sink.
Close() error
}
LogEventSink outputs log events to a destination.
type LogValue ¶
type LogValue interface {
// LogValue returns the value to be logged. This can be a simple type
// (string, number, bool) or a complex type (struct, map, slice).
// The returned value may itself be destructured if it's complex.
LogValue() interface{}
}
LogValue is an optional interface that types can implement to provide custom log representations. When a type implements this interface, the destructurer will use the returned value instead of using reflection.
type Logger ¶
type Logger interface {
// Verbose writes a verbose-level log event.
Verbose(messageTemplate string, args ...interface{})
// Debug writes a debug-level log event.
Debug(messageTemplate string, args ...interface{})
// Information writes an information-level log event.
Information(messageTemplate string, args ...interface{})
// Warning writes a warning-level log event.
Warning(messageTemplate string, args ...interface{})
// Error writes an error-level log event.
Error(messageTemplate string, args ...interface{})
// Fatal writes a fatal-level log event.
Fatal(messageTemplate string, args ...interface{})
// Write writes a log event at the specified level.
Write(level LogEventLevel, messageTemplate string, args ...interface{})
// ForContext creates a logger that enriches events with the specified property.
ForContext(propertyName string, value interface{}) Logger
// WithContext creates a logger that enriches events with context values.
WithContext(ctx context.Context) Logger
// IsEnabled returns true if events at the specified level would be processed.
IsEnabled(level LogEventLevel) bool
// Info writes an information-level log event (alias for Information).
Info(messageTemplate string, args ...interface{})
// Warn writes a warning-level log event (alias for Warning).
Warn(messageTemplate string, args ...interface{})
}
Logger is the main logging interface providing structured logging methods.
type PropertyBag ¶
type PropertyBag struct {
// contains filtered or unexported fields
}
PropertyBag is a type-safe property collection
func (*PropertyBag) Add ¶
func (pb *PropertyBag) Add(name string, value interface{})
Add adds a typed property to the bag
func (*PropertyBag) Get ¶
func (pb *PropertyBag) Get(name string) (interface{}, bool)
Get retrieves a property from the bag
func (*PropertyBag) Properties ¶
func (pb *PropertyBag) Properties() map[string]interface{}
Properties returns all properties as a map
type PropertyValue ¶
type PropertyValue[T any] struct { // contains filtered or unexported fields }
PropertyValue represents a typed property value using generics
func NewPropertyValue ¶
func NewPropertyValue[T any](value T) PropertyValue[T]
NewPropertyValue creates a new typed property value
func (PropertyValue[T]) ToLogEventProperty ¶
func (p PropertyValue[T]) ToLogEventProperty(name string, factory LogEventPropertyFactory) *LogEventProperty
ToLogEventProperty converts to a LogEventProperty
func (PropertyValue[T]) Value ¶
func (p PropertyValue[T]) Value() T
Value returns the underlying value
type SimpleSink ¶
type SimpleSink interface {
LogEventSink
// EmitSimple writes a simple log message without allocations.
EmitSimple(timestamp time.Time, level LogEventLevel, message string)
}
SimpleSink is an optional interface for sinks that support zero-allocation simple logging.