View Source Zexbox.Logging (Zexbox v0.7.0)

This module is responsible for attaching logging to telemetry events.

To use this module, you must have the Telemetry library installed. To do so, add {:telemetry, "~> 1.2.1"} to your list of dependencies in mix.exs.

Summary

Functions

Attaches logging to the Phoenix endpoint stop and start events. By default will be attached on supervisor startup

Attaches logging to the given event with the given params.

Functions

Link to this function

attach_controller_logs()

View Source
@spec attach_controller_logs() :: :ok

Attaches logging to the Phoenix endpoint stop and start events. By default will be attached on supervisor startup

Link to this function

attach_telemetry(event, params, function)

View Source
@spec attach_telemetry(binary(), [atom()], (any(), any(), any(), any() -> any())) ::
  :ok

Attaches logging to the given event with the given params.

To attach metrics for a custom event :my_event with parameters [:my, :event], and a custom handler function my_handler/3, you can do the following:

defmodule MyAppHandler do
  def my_handler(event, measurements, metadata) do
    # Your custom handler implementation here
  end
end

def start(_type, _args) do
  Zexbox.Logging.attach_telemetry(:my_event, [:my, :event], &MyAppHandler.my_handler/3)
end

In this example, when :my_event is triggered, the telemetry system will call MyAppHandler.my_handler/1 with the captured event data. Ensure that the handler function is implemented appropriately for your specific use case.

Note: The logs will only be attached if the application environment variable :capture_telemetry_log_events is set to true.

Parameters

  • event (binary()) - The name of the event to which metrics will be attached.
  • params (list(atom())) - A list of parameters representing the context of the event.
  • function (any(), any(), any(), any() -> any()) - The function to be called when the event occurs.

Returns :ok if the logs are successfully attached.