View Source TelemetryLogger behaviour (TelemetryLogger v0.0.1)
Defines a behaviour for loggers based on telemetry events.
It also contains a helper function attach_loggers/1
to attach to the
:telemetry
runtime and start logging results.
Link to this section Summary
Functions
Attaches to :telemetry
and forward events to telemetry loggers and then
calls Logger properly.
Link to this section Callbacks
Link to this callback
handle_event( event_name, event_measurements, event_metadata, handler_config )
View Source@callback handle_event( :telemetry.event_name(), :telemetry.event_measurements(), :telemetry.event_metadata(), :telemetry.handler_config() ) :: {:log, Logger.level(), Logger.message(), Logger.metadata() | %{required(atom()) => term()}} | :skip
@callback init(keyword()) :: {:ok, [:telemetry.event_name()], :telemetry.handler_config()} | {:error, term()}
Link to this section Functions
@spec attach_loggers([module() | {module(), keyword()}]) :: :ok | {:error, {:already_exists, [{atom(), keyword()}]}}
Attaches to :telemetry
and forward events to telemetry loggers and then
calls Logger properly.
The values on the logger list are passed to init/1
callback.
Example:
TelemetryLogger.attach_loggers(
MyLogger,
{AnotherLogger, something: 1234}
)
Will result in calls MyLogger.init([])
and AnotherLogger.init(something: 1234)
which will then be passed as the last argument to
MyLogger.handle_event/4
and AnotherLogger.handle_event/4
respectively.