observer

package
v0.86.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package observer provides an optional hook that receives agent-internal logs. The logger setup attaches the handler returned by NewHandler to the logger it builds, so any record that passes level filtering is forwarded to the observer registered with SetLogObserver.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetLoggerName

func GetLoggerName() string

GetLoggerName returns the recorded logger name (if any).

func NewHandler

func NewHandler() slog.Handler

NewHandler returns a slog handler that forwards the records it receives to the observer registered with SetLogObserver, if any, and drops them otherwise. Attach it downstream of the async handler — inside the multi-handler it drains — so the observer callback is invoked by the drain loop, one record at a time: it never runs concurrently with itself, and a record is observed before it is written.

func SetLogObserver

func SetLogObserver(h LogObserver)

SetLogObserver registers a process-wide log observer hook. Passing nil disables observation.

func SetLoggerName

func SetLoggerName(name string)

SetLoggerName records the current logger name (e.g. CORE, DOGSTATSD) for low-cardinality tagging. This is optional; if unset, GetLoggerName returns "".

func SimulateLogEmit

func SimulateLogEmit(level types.LogLevel, message string)

SimulateLogEmit invokes the registered LogObserver directly (if any). Intended for tests that need to trigger the observer without going through the logger.

Types

type LogObserver

type LogObserver func(level types.LogLevel, message string)

LogObserver is an optional hook that receives agent-internal logs (already formatted and scrubbed) after level filtering but before they are written to the underlying logger.

Observers MUST be fast and MUST NOT block. Implementations should treat this callback as best-effort.

Jump to

Keyboard shortcuts

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