selflog

package
v0.7.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2025 License: MIT Imports: 6 Imported by: 3

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 Disable

func Disable()

Disable deactivates self-logging.

func Enable

func Enable(w io.Writer)

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)
}

func Printf

func Printf(format string, args ...any)

Printf logs an internal diagnostic message. This is called by mtlog internals and can be called by custom sinks. The format string should include the component in square brackets, e.g., "[console] write failed: %v"

func Sync

func Sync(w io.Writer) io.Writer

Sync wraps a writer to make it thread-safe. Use this when enabling file output or other non-synchronized writers.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL