Documentation
¶
Overview ¶
Package selflog provides internal diagnostic logging for mtlog.
When enabled, selflog captures internal errors and warnings that would otherwise be silently discarded. This is useful for debugging configuration issues or understanding why logs aren't appearing as expected.
Usage ¶
Enable selflog to write to stderr:
selflog.Enable(os.Stderr) defer selflog.Disable()
Enable with a custom handler:
selflog.EnableFunc(func(msg string) {
syslog.Warning("mtlog: " + msg)
})
For thread-safe file logging:
f, _ := os.Create("mtlog-debug.log")
selflog.Enable(selflog.Sync(f))
Format ¶
Messages are formatted as:
2025-01-29T15:30:45Z [component] message details
Environment Variable ¶
Set MTLOG_SELFLOG to automatically enable on startup:
- "stderr" - log to standard error
- "stdout" - log to standard output
- "/path/to/file" - log to specified file
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Enable ¶
Enable activates self-logging to the provided writer. The writer should be thread-safe or wrapped with Sync().
func EnableFunc ¶
func EnableFunc(fn func(string))
EnableFunc activates self-logging using a callback function. The function will be called with formatted log messages.
func IsEnabled ¶
func IsEnabled() bool
IsEnabled returns true if selflog is currently enabled. Use this to avoid formatting costs when disabled:
if selflog.IsEnabled() {
selflog.Printf("[sink] processed %d events", count)
}
Types ¶
This section is empty.