Documentation
¶
Index ¶
- Variables
- func Build(opts ...Option) (*logger, error)
- func ExtractTypeName[T any](options TypeNameOptions) string
- func ExtractTypeNameWithCacheKey[T any](options TypeNameOptions, cacheKeyPrefix string) string
- func ForType[T any](logger core.Logger) core.Logger
- func ForTypeWithCacheKey[T any](logger core.Logger, cacheKeyPrefix string) core.Logger
- func GetTypeNameSimple[T any]() string
- func GetTypeNameWithPackage[T any]() string
- func New(opts ...Option) *logger
- func NewSlogLogger(options ...Option) *slog.Logger
- func PushProperty(ctx context.Context, name string, value any) context.Context
- func ResetTypeNameCache()
- func WithControlledLevel(initialLevel core.LogEventLevel) (Option, *LoggingLevelSwitch)
- func WithSeqLevelControl(serverURL string, options SeqLevelControllerOptions, ...) (Option, *LoggingLevelSwitch, *SeqLevelController)
- type LogBuilder
- 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 WithAutoSourceContext() Option
- func WithCallers(skip int) Option
- func WithCallersInfo() Option
- func WithCapturer(capturer core.Capturer) Option
- func WithCapturing() Option
- func WithCapturingDepth(maxDepth int) Option
- func WithCommonEnvironment() Option
- func WithConsole() Option
- func WithConsoleProperties() Option
- func WithConsoleTemplate(template string) Option
- func WithConsoleTheme(theme *sinks.ConsoleTheme) Option
- func WithCorrelationId(correlationId string) Option
- func WithCustomCapturing(maxDepth, maxStringLength, maxCollectionCount 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 WithFileTemplate(path string, template 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 WithMinimumLevelOverrides(defaultLevel core.LogEventLevel, overrides map[string]core.LogEventLevel) Option
- func WithProcess() Option
- func WithProcessInfo() Option
- func WithProperties(properties map[string]any) Option
- func WithProperty(name string, value any) Option
- func WithPropertyFilter(propertyName string, expectedValue any) 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 WithSourceContext(sourceContext string) Option
- func WithSplunk(url, token string) Option
- func WithSplunkAdvanced(url, token string, opts ...sinks.SplunkOption) Option
- func WithThreadId() Option
- func WithTimestamp() Option
- type Repository
- 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 TypeNameCacheStats
- type TypeNameOptions
- type TypedLogger
- func (l *TypedLogger[T]) DebugT(messageTemplate string, value T, args ...any)
- func (l *TypedLogger[T]) ErrorT(messageTemplate string, value T, args ...any)
- func (l *TypedLogger[T]) FatalT(messageTemplate string, value T, args ...any)
- func (l *TypedLogger[T]) ForContextT(propertyName string, value T) LoggerG[T]
- func (l *TypedLogger[T]) InfoT(messageTemplate string, value T, args ...any)
- func (l *TypedLogger[T]) InformationT(messageTemplate string, value T, args ...any)
- func (l *TypedLogger[T]) VerboseT(messageTemplate string, value T, args ...any)
- func (l *TypedLogger[T]) WarnT(messageTemplate string, value T, args ...any)
- func (l *TypedLogger[T]) WarningT(messageTemplate string, value T, args ...any)
- type UserRepository
Constants ¶
This section is empty.
Variables ¶
var DefaultTypeNameOptions = TypeNameOptions{ IncludePackage: false, PackageDepth: 1, Prefix: "", Suffix: "", SimplifyAnonymous: false, WarnOnUnknown: true, }
DefaultTypeNameOptions provides sensible defaults for type name extraction.
Functions ¶
func Build ¶ added in v0.2.0
Build creates a new logger with the specified options. Returns an error if any option fails during configuration.
func ExtractTypeName ¶ added in v0.3.0
func ExtractTypeName[T any](options TypeNameOptions) string
ExtractTypeName extracts a string representation of the type T using the provided options. This is the exported version of extractTypeName for creating custom loggers.
func ExtractTypeNameWithCacheKey ¶ added in v0.3.0
func ExtractTypeNameWithCacheKey[T any](options TypeNameOptions, cacheKeyPrefix string) string
ExtractTypeNameWithCacheKey extracts a string representation of the type T using the provided options and a custom cache key prefix for multi-tenant scenarios. The cacheKeyPrefix allows for separate cache namespaces, useful in multi-tenant applications where different tenants might have different type naming requirements.
Example usage:
tenantPrefix := fmt.Sprintf("tenant:%s", tenantID) name := ExtractTypeNameWithCacheKey[User](options, tenantPrefix) logger := baseLogger.ForContext("SourceContext", name)
func ForType ¶ added in v0.3.0
ForType creates a logger with SourceContext automatically set from the type name. The type name is extracted using reflection and provides a convenient way to categorize logs by the types they relate to.
By default, only the type name is used (without package). For example:
type User struct { Name string } ForType[User](logger).Information("User created") // SourceContext: "User" ForType[*User](logger).Information("User updated") // SourceContext: "User" (pointer dereferenced)
This is equivalent to:
logger.ForContext("SourceContext", "User").Information("User created")
But more convenient and less error-prone for type-specific logging.
Performance: Uses reflection for type name extraction, which incurs a small performance overhead (~7%) compared to manual ForSourceContext. For high-performance scenarios, consider using ForSourceContext with string literals.
Edge Cases:
- Anonymous structs: Return their full definition (e.g., "struct { Name string }")
- Interfaces: Return "Unknown" as they have no concrete type name
- Generic types: Include type parameters (e.g., "GenericType[string]")
- Built-in types: Return their standard names (e.g., "string", "int", "[]string")
- Function/channel types: Return their signature (e.g., "func(string) error", "chan string")
For more control over type name formatting, use extractTypeName with custom TypeNameOptions. See createCustomLogger in examples/fortype/main.go for a pattern to create custom loggers with TypeNameOptions for specific naming requirements.
func ForTypeWithCacheKey ¶ added in v0.3.0
ForTypeWithCacheKey creates a logger with SourceContext automatically set from the type name using a custom cache key prefix. This is useful in multi-tenant scenarios where different tenants might require separate cache namespaces.
Example usage:
tenantPrefix := fmt.Sprintf("tenant:%s", tenantID) userLogger := ForTypeWithCacheKey[User](logger, tenantPrefix) userLogger.Information("User operation") // SourceContext: "User" (cached per tenant)
func GetTypeNameSimple ¶ added in v0.3.0
GetTypeNameSimple is the exported version of getTypeNameSimple for testing and benchmarking.
func GetTypeNameWithPackage ¶ added in v0.3.0
GetTypeNameWithPackage is the exported version of getTypeNameWithPackage for testing and benchmarking.
func New ¶
func New(opts ...Option) *logger
New creates a new logger with the specified options. If any option returns an error during configuration, New will panic. Use Build() for non-panicking initialization.
func NewSlogLogger ¶
NewSlogLogger creates a new slog.Logger backed by mtlog
func PushProperty ¶ added in v0.3.0
PushProperty adds a property to the context that will be included in all log events created from loggers using this context. Properties are inherited - if a context already has properties, the new context will include both the existing and new properties.
Properties set via PushProperty have the lowest precedence and are overridden by ForContext properties and event-specific properties.
Thread Safety: This function is thread-safe. It creates a new context value with a copy of the properties map, ensuring immutability. Multiple goroutines can safely call PushProperty on the same context, and each will receive its own independent context.
Example:
ctx := context.Background() ctx = mtlog.PushProperty(ctx, "UserId", 123) ctx = mtlog.PushProperty(ctx, "TenantId", "acme-corp") // Both UserId and TenantId will be included in this log logger.WithContext(ctx).Information("Processing user request") // Properties can be overridden at more specific scopes logger.WithContext(ctx).ForContext("UserId", 456).Information("Override test") // Results in UserId=456 (ForContext overrides PushProperty)
func ResetTypeNameCache ¶ added in v0.3.0
func ResetTypeNameCache()
ResetTypeNameCache clears the type name cache and statistics. Useful for testing and benchmarking.
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 any) *LogBuilder
Property adds a property
func (*LogBuilder) PropertyTyped ¶
func (b *LogBuilder) PropertyTyped(name string, value any) *LogBuilder
PropertyTyped adds a typed property
type LoggerG ¶
type LoggerG[T any] interface { // Logging methods with type safety VerboseT(messageTemplate string, value T, args ...any) DebugT(messageTemplate string, value T, args ...any) InformationT(messageTemplate string, value T, args ...any) WarningT(messageTemplate string, value T, args ...any) ErrorT(messageTemplate string, value T, args ...any) FatalT(messageTemplate string, value T, args ...any) // Short method names InfoT(messageTemplate string, value T, args ...any) WarnT(messageTemplate string, value T, args ...any) // 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 WithAutoSourceContext ¶ added in v0.2.0
func WithAutoSourceContext() Option
WithAutoSourceContext adds automatic source context detection.
func WithCallers ¶
WithCallers adds caller information enrichment.
func WithCallersInfo ¶
func WithCallersInfo() Option
WithCallersInfo adds caller information enrichment with default skip.
func WithCapturer ¶ added in v0.6.0
WithCapturer sets the capturer for the pipeline.
func WithCapturing ¶ added in v0.6.0
func WithCapturing() Option
WithCapturing adds the cached capturer for better performance.
func WithCapturingDepth ¶ added in v0.6.0
WithCapturingDepth adds capturing with a specific max depth.
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 WithConsoleTemplate ¶ added in v0.2.0
WithConsoleTemplate adds a console sink with a custom output template.
func WithConsoleTheme ¶ added in v0.2.0
func WithConsoleTheme(theme *sinks.ConsoleTheme) Option
WithConsoleTheme adds a console sink with a custom theme.
func WithCorrelationId ¶
WithCorrelationId adds a fixed correlation ID to all log events.
func WithCustomCapturing ¶ added in v0.6.0
WithCustomCapturing adds a capturer with custom limits.
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 WithFileTemplate ¶ added in v0.2.0
WithFileTemplate adds a file sink with a custom output template.
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 WithMinimumLevelOverrides ¶ added in v0.2.0
func WithMinimumLevelOverrides(defaultLevel core.LogEventLevel, overrides map[string]core.LogEventLevel) Option
WithMinimumLevelOverrides adds source context-based level filtering.
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 WithSourceContext ¶ added in v0.2.0
WithSourceContext adds source context enrichment with the specified context.
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 Repository ¶ added in v0.3.0
Repository interface for testing - used across multiple test files
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 TypeNameCacheStats ¶ added in v0.3.0
type TypeNameCacheStats struct { Hits int64 // Number of cache hits Misses int64 // Number of cache misses Evictions int64 // Number of cache evictions due to LRU policy HitRatio float64 // Hit ratio as a percentage (0-100) Size int64 // Number of entries currently in the cache MaxSize int64 // Maximum cache size before eviction }
TypeNameCacheStats provides performance statistics for the type name cache.
func GetTypeNameCacheStats ¶ added in v0.3.0
func GetTypeNameCacheStats() TypeNameCacheStats
GetTypeNameCacheStats returns current cache performance statistics.
type TypeNameOptions ¶ added in v0.3.0
type TypeNameOptions struct { // IncludePackage determines whether to include the package path in the type name. // Default: false (only type name) IncludePackage bool // PackageDepth limits how many package path segments to include when IncludePackage is true. // 0 means include full package path. Default: 1 (only immediate package) PackageDepth int // Prefix is prepended to the type name for consistent naming. // Example: "MyApp." would result in "MyApp.User" for User type Prefix string // Suffix is appended to the type name. // Example: ".Service" would result in "User.Service" for User type Suffix string // SimplifyAnonymous controls how anonymous struct types are displayed. // When true, anonymous structs return "AnonymousStruct" instead of their full definition. // Default: false (shows full struct definition) SimplifyAnonymous bool // WarnOnUnknown controls whether to log warnings for "Unknown" type names. // When true, warnings are logged to help with debugging interface types and unresolvable types. // When false, warnings are suppressed to reduce log noise in production. // Default: true (warnings enabled) WarnOnUnknown bool }
TypeNameOptions controls how type names are extracted and formatted for SourceContext.
Use with extractTypeName to create custom loggers with more control over type name formatting than the default ForType function. See examples/fortype/main.go demonstrateTypeNameOptions for practical usage examples.
Example:
opts := TypeNameOptions{IncludePackage: true, Prefix: "MyApp."} name := extractTypeName[User](opts) // Result: "MyApp.mypackage.User" logger := baseLogger.ForContext("SourceContext", name)
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 ...any)
DebugT logs at debug level with typed value
func (*TypedLogger[T]) ErrorT ¶
func (l *TypedLogger[T]) ErrorT(messageTemplate string, value T, args ...any)
ErrorT logs at error level with typed value
func (*TypedLogger[T]) FatalT ¶
func (l *TypedLogger[T]) FatalT(messageTemplate string, value T, args ...any)
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 ...any)
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 ...any)
InformationT logs at information level with typed value
func (*TypedLogger[T]) VerboseT ¶
func (l *TypedLogger[T]) VerboseT(messageTemplate string, value T, args ...any)
VerboseT logs at verbose level with typed value
func (*TypedLogger[T]) WarnT ¶
func (l *TypedLogger[T]) WarnT(messageTemplate string, value T, args ...any)
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 ...any)
WarningT logs at warning level with typed value
type UserRepository ¶ added in v0.3.0
type UserRepository struct{}
UserRepository implements Repository for testing
func (*UserRepository) Save ¶ added in v0.3.0
func (ur *UserRepository) Save(any) error
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
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
|
|
capturing
command
|
|
configuration
command
|
|
context
command
|
|
durable
command
|
|
dynamic-levels
command
|
|
elasticsearch
command
|
|
enrichers
command
|
|
filtering
command
|
|
fortype
command
Package main demonstrates using ForType for automatic SourceContext from type names.
|
Package main demonstrates using ForType for automatic SourceContext from type names. |
generics
command
|
|
go-templates
command
|
|
logcontext
command
Package main demonstrates using LogContext for scoped properties.
|
Package main demonstrates using LogContext for scoped properties. |
logvalue
command
|
|
otel
command
Package main demonstrates using OTEL-style dotted property names with mtlog.
|
Package main demonstrates using OTEL-style dotted property names with mtlog. |
output-templates
command
|
|
rolling
command
|
|
seq
command
|
|
showcase
command
|
|
splunk
command
|
|
themes
command
|
|
goland-plugin
|
|
src/test/resources/testData
command
|
|
internal
|
|
Package selflog provides internal diagnostic logging for mtlog.
|
Package selflog provides internal diagnostic logging for mtlog. |