Documentation
¶
Overview ¶
Package observe provides a lightweight observer facade for logs and key process events.
The observer is optional. If no observer is set, the library uses its built-in logger and metrics providers. When an observer is set, log calls are delegated to it, allowing fully custom telemetry without coupling to slog.
Index ¶
- func SetObserver(o Observer)
- type NoOpObserver
- func (NoOpObserver) LogDebug(string, ...any)
- func (NoOpObserver) LogError(string, ...any)
- func (NoOpObserver) LogInfo(string, ...any)
- func (NoOpObserver) LogWarn(string, ...any)
- func (NoOpObserver) OnGoroutinePanicked(any, []byte)
- func (NoOpObserver) OnProcessFailed(error)
- func (NoOpObserver) OnProcessStarted(int)
- type Observer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetObserver ¶
func SetObserver(o Observer)
SetObserver configures the global observer.
Passing nil disables observer routing and falls back to the default logger.
Types ¶
type NoOpObserver ¶
type NoOpObserver struct{}
NoOpObserver provides a drop-in observer that does nothing.
func (NoOpObserver) LogDebug ¶
func (NoOpObserver) LogDebug(string, ...any)
func (NoOpObserver) LogError ¶
func (NoOpObserver) LogError(string, ...any)
func (NoOpObserver) LogInfo ¶
func (NoOpObserver) LogInfo(string, ...any)
func (NoOpObserver) LogWarn ¶
func (NoOpObserver) LogWarn(string, ...any)
func (NoOpObserver) OnGoroutinePanicked ¶ added in v1.6.0
func (NoOpObserver) OnGoroutinePanicked(any, []byte)
func (NoOpObserver) OnProcessFailed ¶
func (NoOpObserver) OnProcessFailed(error)
func (NoOpObserver) OnProcessStarted ¶
func (NoOpObserver) OnProcessStarted(int)
type Observer ¶
type Observer interface {
OnProcessStarted(pid int)
OnProcessFailed(err error)
OnGoroutinePanicked(recovered any, stack []byte)
LogDebug(msg string, args ...any)
LogInfo(msg string, args ...any)
LogWarn(msg string, args ...any)
LogError(msg string, args ...any)
}
Observer allows external packages to plug in observability (logs and process events) without coupling to specific implementations.
Stable as of v1.6.0. Implementations should avoid calling the lifecycle log package directly to prevent recursive logging loops.
OnGoroutinePanicked hook (v1.6.0): Invoked when a background task panics. Stack bytes are optional (depends on WithStackCapture configuration). Behavior details: See docs/LIMITATIONS.md (API Stability section) and docs/TECHNICAL.md §14.
func GetObserver ¶
func GetObserver() Observer
GetObserver returns the current global observer, if any.