Documentation
¶
Overview ¶
Package multilog provides a multi-logger that can log to multiple destinations.
Index ¶
- Constants
- Variables
- func AddPrefixSuffix(value string, opts *CustomHandlerOptions) string
- func BaseName(file string) string
- func Contains(slice []string, item string) bool
- func ContainsKey(keys []string, key string) bool
- func CreateHandlers(config *Config) ([]slog.Handler, error)
- func CreateRotationWriter(opts CustomHandlerOptions) *bufio.Writer
- func GetCallerInfo(identifiers ...string) (fn, file string, line int, found bool)
- func GetLevelName(level slog.Level) string
- func GetOtherCallerInfo() (fn, file string, line int, found bool)
- func GetOtherSourceValue(fn, file string, line int) string
- func GetPerfCallerInfo() (fn, file string, line int, found bool)
- func GetPerformanceMetrics() string
- func GetPerformanceMetricsUsingRuntime() string
- func GetPerformanceMetricsWithMemStats() string
- func GetPlaceholderValues(sb *strings.Builder, record slog.Record, placeholders []string, ...) map[string]interface{}
- func GetPlaceholders(format string) []string
- func GetSlogLevel(level string) slog.Level
- func GetSourceValue(level slog.Level, sb *strings.Builder, ...) string
- func NewConsoleHandler(opts CustomHandlerOptions) slog.Handler
- func NewFileHandler(opts CustomHandlerOptions) (slog.Handler, error)
- func NewJSONHandler(opts CustomHandlerOptions, replaceAttr CustomReplaceAttr) (slog.Handler, error)
- func NewTestLogger(t *testing.T) (*Logger, *TestHandler)
- func Remove(key string, a slog.Attr) slog.Attr
- func RemoveKey(key string) func(groups []string, a slog.Attr) slog.Attr
- func RemovePlaceholderChars(values map[string]interface{}) map[string]interface{}
- func TrimSpaces(placeholders []string) []string
- type Aggregator
- type Config
- type ConsoleHandler
- type ContextLogger
- func (l *ContextLogger) Debug(msg string, args ...any)
- func (l *ContextLogger) DebugContext(ctx context.Context, msg string, args ...any)
- func (l *ContextLogger) Debugf(msg string, args ...any)
- func (l *ContextLogger) Error(msg string, args ...any)
- func (l *ContextLogger) ErrorContext(ctx context.Context, msg string, args ...any)
- func (l *ContextLogger) Errorf(msg string, args ...any)
- func (l *ContextLogger) Info(msg string, args ...any)
- func (l *ContextLogger) InfoContext(ctx context.Context, msg string, args ...any)
- func (l *ContextLogger) Infof(msg string, args ...any)
- func (l *ContextLogger) Perf(msg string, args ...any)
- func (l *ContextLogger) PerfContext(ctx context.Context, msg string, args ...any)
- func (l *ContextLogger) Perff(msg string, args ...any)
- func (l *ContextLogger) Warn(msg string, args ...any)
- func (l *ContextLogger) WarnContext(ctx context.Context, msg string, args ...any)
- func (l *ContextLogger) Warnf(msg string, args ...any)
- func (l *ContextLogger) WithContext(ctx context.Context) LoggerInterface
- func (l *ContextLogger) WithField(key string, value any) LoggerInterface
- func (l *ContextLogger) WithFields(fields map[string]any) LoggerInterface
- type CustomHandler
- func (ch *CustomHandler) Enabled(ctx context.Context, level slog.Level) bool
- func (ch *CustomHandler) GetKeyValue(key string, sb *strings.Builder, removeKey bool) string
- func (ch *CustomHandler) GetOptions() *CustomHandlerOptions
- func (ch *CustomHandler) GetSlogHandler() slog.Handler
- func (ch *CustomHandler) GetStringBuilder() *strings.Builder
- func (ch *CustomHandler) GetWriter() *bufio.Writer
- func (ch *CustomHandler) Handle(ctx context.Context, record slog.Record) error
- func (ch *CustomHandler) WithAttrs(attrs []slog.Attr) slog.Handler
- func (ch *CustomHandler) WithGroup(name string) slog.Handler
- type CustomHandlerInterface
- type CustomHandlerOptions
- type CustomReplaceAttr
- type FileHandler
- type HandlerConfig
- type JSONHandler
- func (jh *JSONHandler) Enabled(ctx context.Context, level slog.Level) bool
- func (jh *JSONHandler) GetKeyValue(key string, sb *strings.Builder, removeKey bool) string
- func (jh *JSONHandler) Handle(ctx context.Context, record slog.Record) error
- func (jh *JSONHandler) WithAttrs(attrs []slog.Attr) slog.Handler
- func (jh *JSONHandler) WithGroup(name string) slog.Handler
- type LogConfig
- type LogRecord
- type LogRecordFormat
- type Logger
- func (l *Logger) Debug(msg string, args ...any)
- func (l *Logger) DebugContext(ctx context.Context, msg string, args ...any)
- func (l *Logger) Debugf(msg string, args ...any)
- func (l *Logger) Error(msg string, args ...any)
- func (l *Logger) ErrorContext(ctx context.Context, msg string, args ...any)
- func (l *Logger) Errorf(msg string, args ...any)
- func (l *Logger) GetLogger() *slog.Logger
- func (l *Logger) Info(msg string, args ...any)
- func (l *Logger) InfoContext(ctx context.Context, msg string, args ...any)
- func (l *Logger) Infof(msg string, args ...any)
- func (l *Logger) Perf(msg string, args ...any)
- func (l *Logger) PerfContext(ctx context.Context, msg string, args ...any)
- func (l *Logger) Perff(msg string, args ...any)
- func (l *Logger) Warn(msg string, args ...any)
- func (l *Logger) WarnContext(ctx context.Context, msg string, args ...any)
- func (l *Logger) Warnf(msg string, args ...any)
- func (l *Logger) WithContext(ctx context.Context) LoggerInterface
- func (l *Logger) WithField(key string, value any) LoggerInterface
- func (l *Logger) WithFields(fields map[string]any) LoggerInterface
- func (l *Logger) WithLevel(_ slog.Level) *Logger
- type LoggerInterface
- type PerfMetrics
- type SourceInfo
- type TestHandler
- func (h *TestHandler) Called() bool
- func (h *TestHandler) Enabled(_ context.Context, _ slog.Level) bool
- func (h *TestHandler) Handle(_ context.Context, r slog.Record) error
- func (h *TestHandler) LastLevel() slog.Level
- func (h *TestHandler) LastMessage() string
- func (h *TestHandler) Reset()
- func (h *TestHandler) WithAttrs(_ []slog.Attr) slog.Handler
- func (h *TestHandler) WithGroup(_ string) slog.Handler
- type WriterHandler
Constants ¶
const ( DefaultTimeFormat = "15:04:05" DefaultDateTimeFormat = "2006-01-02 15:04:05" DefaultDateFormat = "2006-01-02" )
Default time and date formats
const ( DefaultLogFileSize = 5 // in megabytes DefaultLogFileBackups = 1 DefaultLogFileAge = 1 // in days )
Default log file settings
const ( DebugLevel = "debug" InfoLevel = "info" WarnLevel = "warn" ErrorLevel = "error" PerfLevel = "perf" )
Log levels
const ( FileHandlerType = "file" ConsoleHandlerType = "console" )
Handler types
const ( TextHandlerSubType = "text" JSONHandlerSubType = "json" )
Subtypes for file handlers
const ( DefaultValuePrefixChar = "" DefaultValueSuffixChar = "" )
Default value prefix and suffix characters
const ( DefaultSuffixStartChar = "[" DefaultSuffixEndChar = "]" )
Default suffix characters
const ( DefaultPerfStartChar = "[" DefaultPerfEndChar = "]" )
Default performance metrics characters
const ( DefaultPlaceholderPrefixChar = "[" DefaultPlaceholderSuffixChar = "]" )
Default placeholder prefix and suffix characters
const ( DatePlaceholder = "[date]" TimePlaceholder = "[time]" DateTimePlaceholder = "[datetime]" LevelPlaceholder = "[level]" MsgPlaceholder = "[msg]" PerfPlaceholder = "[perf]" SourcePlaceholder = "[source]" )
Pattern placeholders
const ( FileSource = "[file]" LineSource = "[line]" FuncSource = "[func]" )
Source placeholders
const ( DefaultFormat = "[time] [level] [msg]" DefaultPerfFormat = "[time] [level] [perf] [msg]" DefaultDebugFormat = "[time] [level] [perf] [msg] [source]" DefaultErrorFormat = "[time] [level] [msg] [source]" DefaultSourceFormat = "[file]:[line]:[func]" DefaultPerfSourceFormat = DefaultSourceFormat )
Default log formats
const ( UnknownLevel = "unknown" UnknownSource = "unknown" DefaultSLogLevel = slog.LevelInfo DefaultLogLevel = "info" LevelPerf = slog.Level(-1) )
Log level constants
const GenericLogFuncName = "multilog.(*Logger).log"
GenericLogFuncName is the function name used for generic logging.
const PackagePrefix = "multilog.(*Logger)."
PackagePrefix is the prefix used for package-level logging.
Variables ¶
var ( RemoveTimeKey = RemoveKey(slog.TimeKey) RemoveLevelKey = RemoveKey(slog.LevelKey) RemoveSourceKey = RemoveKey(slog.SourceKey) RemoveMessageKey = RemoveKey(slog.MessageKey) )
RemoveTimeKey, RemoveLevelKey, RemoveSourceKey, and RemoveMessageKey are functions
var CallIdentifiers = []string{
"Perf(",
"Perff(",
"Infof(",
"Warnf(",
"Debugf(",
"Errorf(",
}
CallIdentifiers contains the identifiers for various logging functions.
var DefaultPatternPlaceholders = []string{ DateTimePlaceholder, LevelPlaceholder, MsgPlaceholder, SourcePlaceholder, }
DefaultPatternPlaceholders represents the default pattern placeholders.
var LevelMap = map[string]slog.Level{ "debug": slog.LevelDebug, "info": slog.LevelInfo, "warn": slog.LevelWarn, "error": slog.LevelError, "perf": LevelPerf, }
LevelMap maps string to slog.Level.
var LevelNamesMap = map[slog.Leveler]string{ slog.LevelDebug: "debug", slog.LevelInfo: "info", slog.LevelWarn: "warn", slog.LevelError: "error", LevelPerf: "perf", }
LevelNamesMap maps slog.Level to string.
var LogLevels = []string{DebugLevel, InfoLevel, WarnLevel, ErrorLevel, PerfLevel}
LogLevels contains all supported log levels.
Functions ¶
func AddPrefixSuffix ¶
func AddPrefixSuffix(value string, opts *CustomHandlerOptions) string
AddPrefixSuffix adds the prefix and suffix to the value.
func ContainsKey ¶
ContainsKey checks if the given key is present in the keys.
func CreateHandlers ¶
CreateHandlers creates the handlers based on the configuration.
func CreateRotationWriter ¶
func CreateRotationWriter(opts CustomHandlerOptions) *bufio.Writer
CreateRotationWriter creates a rotation writer for the given options.
func GetCallerInfo ¶
GetCallerInfo retrieves the caller information from the stack trace.
func GetLevelName ¶
GetLevelName returns the string representation of the slog.Level.
func GetOtherCallerInfo ¶
GetOtherCallerInfo returns the caller information for other logs.
func GetOtherSourceValue ¶
GetOtherSourceValue returns the source value for other logs.
func GetPerfCallerInfo ¶
GetPerfCallerInfo returns the caller information for performance logs.
func GetPerformanceMetrics ¶
func GetPerformanceMetrics() string
GetPerformanceMetrics gathers memory and goroutine metrics.
func GetPerformanceMetricsUsingRuntime ¶
func GetPerformanceMetricsUsingRuntime() string
GetPerformanceMetricsUsingRuntime gathers memory and goroutine metrics.
func GetPerformanceMetricsWithMemStats ¶
func GetPerformanceMetricsWithMemStats() string
GetPerformanceMetricsWithMemStats gathers memory and goroutine metrics.
func GetPlaceholderValues ¶
func GetPlaceholderValues( sb *strings.Builder, record slog.Record, placeholders []string, getKeyValue func(string, *strings.Builder, bool) string, ) map[string]interface{}
GetPlaceholderValues returns the placeholder values.
func GetPlaceholders ¶
GetPlaceholders returns the placeholders from the format.
func GetSlogLevel ¶
GetSlogLevel returns the slog.Level for the given level string.
func GetSourceValue ¶
func GetSourceValue( level slog.Level, sb *strings.Builder, getKeyValue func(string, *strings.Builder, bool) string, ) string
GetSourceValue returns the source value.
func NewConsoleHandler ¶
func NewConsoleHandler(opts CustomHandlerOptions) slog.Handler
NewConsoleHandler creates a console Handler with the specified options.
func NewFileHandler ¶
func NewFileHandler(opts CustomHandlerOptions) (slog.Handler, error)
NewFileHandler creates a file Handler with the specified options.
func NewJSONHandler ¶
func NewJSONHandler( opts CustomHandlerOptions, replaceAttr CustomReplaceAttr, ) (slog.Handler, error)
NewJSONHandler creates a JSON Handler with the specified options.
func NewTestLogger ¶
func NewTestLogger(t *testing.T) (*Logger, *TestHandler)
NewTestLogger creates a new Logger instance with the given handler.
func RemovePlaceholderChars ¶
RemovePlaceholderChars removes the placeholder characters from the values.
func TrimSpaces ¶
TrimSpaces trims the spaces from the placeholders.
Types ¶
type Aggregator ¶
Aggregator is a handler that forwards logs to multiple handlers.
func NewAggregator ¶
func NewAggregator(handlers ...slog.Handler) Aggregator
NewAggregator creates a new aggregator with the given handlers.
type Config ¶
type Config struct {
Multilog LogConfig `yaml:"multilog"`
}
Config represents the configuration for the application.
func NewConfigFromData ¶
NewConfigFromData loads the configuration from the provided YAML data.
func (*Config) GetCustomHandlerOptionsForHandler ¶
func (c *Config) GetCustomHandlerOptionsForHandler( handlerConfig HandlerConfig, ) (CustomHandlerOptions, error)
GetCustomHandlerOptionsForHandler returns the custom handler options for the handler.
func (*Config) GetEnabledHandlers ¶
func (c *Config) GetEnabledHandlers() []HandlerConfig
GetEnabledHandlers returns the list of enabled handlers from the configuration.
type ConsoleHandler ¶
type ConsoleHandler struct {
Handler CustomHandlerInterface
}
ConsoleHandler is a Handler for console logging.
func (*ConsoleHandler) Handle ¶
Handle processes the log record and writes it to the console handler.
type ContextLogger ¶
type ContextLogger struct { *Logger // contains filtered or unexported fields }
ContextLogger wraps a Logger with a context
func (*ContextLogger) Debug ¶
func (l *ContextLogger) Debug(msg string, args ...any)
Debug logs a debug message with structured key-value pairs.
func (*ContextLogger) DebugContext ¶
func (l *ContextLogger) DebugContext(ctx context.Context, msg string, args ...any)
DebugContext logs a debug message
func (*ContextLogger) Debugf ¶
func (l *ContextLogger) Debugf(msg string, args ...any)
Debugf logs a debug message with structured key-value pairs.
func (*ContextLogger) Error ¶
func (l *ContextLogger) Error(msg string, args ...any)
Error logs an error message with structured key-value pairs.
func (*ContextLogger) ErrorContext ¶
func (l *ContextLogger) ErrorContext(ctx context.Context, msg string, args ...any)
ErrorContext logs an error message
func (*ContextLogger) Errorf ¶
func (l *ContextLogger) Errorf(msg string, args ...any)
Errorf logs an error message with structured key-value pairs.
func (*ContextLogger) Info ¶
func (l *ContextLogger) Info(msg string, args ...any)
Info logs an informational message with structured key-value pairs.
func (*ContextLogger) InfoContext ¶
func (l *ContextLogger) InfoContext(ctx context.Context, msg string, args ...any)
InfoContext logs an informational message
func (*ContextLogger) Infof ¶
func (l *ContextLogger) Infof(msg string, args ...any)
Infof logs an informational message with structured key-value pairs.
func (*ContextLogger) Perf ¶
func (l *ContextLogger) Perf(msg string, args ...any)
Perf logs performance metrics statically.
func (*ContextLogger) PerfContext ¶
func (l *ContextLogger) PerfContext(ctx context.Context, msg string, args ...any)
PerfContext logs performance metrics dynamically.
func (*ContextLogger) Perff ¶
func (l *ContextLogger) Perff(msg string, args ...any)
Perff logs performance metrics dynamically.
func (*ContextLogger) Warn ¶
func (l *ContextLogger) Warn(msg string, args ...any)
Warn logs a warning message with structured key-value pairs.
func (*ContextLogger) WarnContext ¶
func (l *ContextLogger) WarnContext(ctx context.Context, msg string, args ...any)
WarnContext logs a warning message
func (*ContextLogger) Warnf ¶
func (l *ContextLogger) Warnf(msg string, args ...any)
Warnf logs a warning message with structured key-value pairs.
func (*ContextLogger) WithContext ¶
func (l *ContextLogger) WithContext(ctx context.Context) LoggerInterface
WithContext for ContextLogger should return a new ContextLogger with the new context
func (*ContextLogger) WithField ¶
func (l *ContextLogger) WithField(key string, value any) LoggerInterface
WithField ensures we maintain the context when adding fields
func (*ContextLogger) WithFields ¶
func (l *ContextLogger) WithFields(fields map[string]any) LoggerInterface
WithFields ensures we maintain the context when adding fields
type CustomHandler ¶
type CustomHandler struct { Opts *CustomHandlerOptions // contains filtered or unexported fields }
CustomHandler is a base handler for logging.
func NewCustomHandler ¶
func NewCustomHandler( customOpts *CustomHandlerOptions, writer *bufio.Writer, replaceAttr CustomReplaceAttr, ) *CustomHandler
NewCustomHandler creates a new handler with a given configuration.
func (*CustomHandler) Enabled ¶
Enabled determines if a log message should be logged based on its level.
func (*CustomHandler) GetKeyValue ¶
GetKeyValue returns the value of a key.
func (*CustomHandler) GetOptions ¶
func (ch *CustomHandler) GetOptions() *CustomHandlerOptions
GetOptions returns the handler options.
func (*CustomHandler) GetSlogHandler ¶
func (ch *CustomHandler) GetSlogHandler() slog.Handler
GetSlogHandler returns the handler slog.Handler.
func (*CustomHandler) GetStringBuilder ¶
func (ch *CustomHandler) GetStringBuilder() *strings.Builder
GetStringBuilder returns the handler string builder.
func (*CustomHandler) GetWriter ¶
func (ch *CustomHandler) GetWriter() *bufio.Writer
GetWriter returns the handler writer.
type CustomHandlerInterface ¶
type CustomHandlerInterface interface { slog.Handler GetOptions() *CustomHandlerOptions GetStringBuilder() *strings.Builder GetKeyValue(key string, sb *strings.Builder, removeKey bool) string GetWriter() *bufio.Writer GetSlogHandler() slog.Handler }
CustomHandlerInterface is an interface for the custom handler.
type CustomHandlerOptions ¶
type CustomHandlerOptions struct { Level string File string ValueSuffixChar string ValuePrefixChar string Pattern string SubType string PatternPlaceholders []string MaxSize int MaxAge int MaxBackups int UseSingleLetterLevel bool AddSource bool Enabled bool }
CustomHandlerOptions contains configuration options for the handler.
type CustomReplaceAttr ¶
CustomReplaceAttr is a function type for replacing attributes.
func GenerateDefaultCustomReplaceAttr ¶
func GenerateDefaultCustomReplaceAttr( opts CustomHandlerOptions, keysToRemove ...string, ) CustomReplaceAttr
GenerateDefaultCustomReplaceAttr returns a default CustomReplaceAttr function.
func RemoveGivenKeys ¶
func RemoveGivenKeys(keys ...string) CustomReplaceAttr
RemoveGivenKeys returns a function that removes the given keys.
func RemoveKeys ¶
func RemoveKeys() CustomReplaceAttr
RemoveKeys returns a function that removes the time, level, source, and message keys.
func ReplaceAttr ¶
func ReplaceAttr(replaceMap map[string]string) CustomReplaceAttr
ReplaceAttr is a function type for replacing attributes.
type FileHandler ¶
type FileHandler struct {
Handler CustomHandlerInterface
}
FileHandler is a Handler for file logging.
type HandlerConfig ¶
type HandlerConfig struct { Type string `yaml:"type"` SubType string `yaml:"subtype,omitempty"` Level string `yaml:"level"` Pattern string `yaml:"pattern,omitempty"` PatternPlaceholders string `yaml:"pattern_placeholders,omitempty"` ValuePrefixChar string `yaml:"value_prefix_char,omitempty"` ValueSuffixChar string `yaml:"value_suffix_char,omitempty"` File string `yaml:"file,omitempty"` MaxSize int `yaml:"max_size,omitempty"` MaxBackups int `yaml:"max_backups,omitempty"` MaxAge int `yaml:"max_age,omitempty"` Enabled bool `yaml:"enabled"` UseSingleLetterLevel bool `yaml:"use_single_letter_level,omitempty"` }
HandlerConfig represents the configuration for a specific handler.
type JSONHandler ¶
type JSONHandler struct {
Handler CustomHandlerInterface
}
JSONHandler is a Handler for JSON logging.
func (*JSONHandler) GetKeyValue ¶
GetKeyValue retrieves the value associated with the given key from the JSON string.
type LogConfig ¶
type LogConfig struct {
Handlers []HandlerConfig `yaml:"handlers"`
}
LogConfig represents the logging configuration.
type LogRecord ¶
type LogRecord struct { Time string Message string Format LogRecordFormat Source SourceInfo PerfMetrics PerfMetrics Level slog.Level }
LogRecord represents a log record with additional information.
type LogRecordFormat ¶
type LogRecordFormat struct {
Pattern string
}
LogRecordFormat represents the format of a log record.
type Logger ¶
Logger wraps slog.Logger and allows configuration of handlers.
func (*Logger) DebugContext ¶
DebugContext logs a debug message with structured key-value pairs.
func (*Logger) ErrorContext ¶
ErrorContext logs an error message with structured key-value pairs.
func (*Logger) InfoContext ¶
InfoContext logs an informational message with structured key-value pairs.
func (*Logger) PerfContext ¶
PerfContext logs performance metrics dynamically.
func (*Logger) WarnContext ¶
WarnContext logs a warning message with structured key-value pairs.
func (*Logger) WithContext ¶
func (l *Logger) WithContext(ctx context.Context) LoggerInterface
WithContext returns a logger with the context attached
func (*Logger) WithField ¶
func (l *Logger) WithField(key string, value any) LoggerInterface
WithField returns a logger with the specified field attached to all messages
func (*Logger) WithFields ¶
func (l *Logger) WithFields(fields map[string]any) LoggerInterface
WithFields returns a logger with the specified fields attached to all messages
type LoggerInterface ¶
type LoggerInterface interface { Perff(msg string, args ...any) Perf(msg string, args ...any) Infof(msg string, args ...any) Warnf(msg string, args ...any) Errorf(msg string, args ...any) Debugf(msg string, args ...any) // Debug Structured logging methods Debug(msg string, args ...any) Info(msg string, args ...any) Warn(msg string, args ...any) Error(msg string, args ...any) // WithContext Context-aware logging methods WithContext(ctx context.Context) LoggerInterface PerfContext(ctx context.Context, msg string, args ...any) InfoContext(ctx context.Context, msg string, args ...any) WarnContext(ctx context.Context, msg string, args ...any) ErrorContext(ctx context.Context, msg string, args ...any) DebugContext(ctx context.Context, msg string, args ...any) // WithField Structured logging methods WithField(key string, value any) LoggerInterface WithFields(fields map[string]any) LoggerInterface // GetLogger Return the underlying logger for advanced usage GetLogger() *slog.Logger }
LoggerInterface defines the logging methods available
type PerfMetrics ¶
type PerfMetrics struct { NumGoroutines int NumCPUs int MaxThreads int GCHeapAllocs uint64 GCHeapFrees uint64 HeapFree uint64 HeapObjects uint64 HeapReleased uint64 HeapUnused uint64 TotalMemory uint64 TotalCPUUsage float64 UserCPUUsage float64 Alloc float64 TotalAlloc float64 Sys float64 HeapAlloc float64 HeapSys float64 HeapIdle float64 HeapInuse float64 StackSys float64 }
PerfMetrics represents performance metrics.
func CollectPerfMetrics ¶
func CollectPerfMetrics() *PerfMetrics
CollectPerfMetrics collects performance metrics.
func CollectPerfMetricsWithMemStats ¶
func CollectPerfMetricsWithMemStats() *PerfMetrics
CollectPerfMetricsWithMemStats collects performance metrics including memory stats.
type SourceInfo ¶
SourceInfo represents the source information of a log record.
type TestHandler ¶
type TestHandler struct {
// contains filtered or unexported fields
}
TestHandler implements slog.Handler for testing purposes
func NewTestHandler ¶
func NewTestHandler(t *testing.T) *TestHandler
NewTestHandler creates a new TestHandler for testing purposes.
func (*TestHandler) Called ¶
func (h *TestHandler) Called() bool
Called returns whether the handler has been called.
func (*TestHandler) LastLevel ¶ added in v0.2.0
func (h *TestHandler) LastLevel() slog.Level
LastLevel returns the last logged level.
func (*TestHandler) LastMessage ¶ added in v0.2.0
func (h *TestHandler) LastMessage() string
LastMessage returns the last logged message.
func (*TestHandler) Reset ¶
func (h *TestHandler) Reset()
Reset resets the handler's state for the next test.
type WriterHandler ¶
WriterHandler is an interface for custom write operations.
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
Package main provides the entry point for the multilog application.
|
Package main provides the entry point for the multilog application. |
Example of using a multilog package for logging with multiple handlers
|
Example of using a multilog package for logging with multiple handlers |