Arrea.Logging.Behaviour behaviour (Arrea v1.0.0)

Copy Markdown View Source

Behaviour contract for custom Arrea Engine loggers.

Implementing this behaviour allows projects to provide their own logger formatter that integrates with Elixir's :logger infrastructure while maintaining full control over formatting and output style.

Usage

defmodule MyApp.Logger do
  @behaviour Arrea.Logging.Behaviour

  @impl true
  def log(:info, message, metadata) do
    IO.puts("[INFO] #{message}")
  end

  @impl true
  def format(level, message, metadata) do
    "#{DateTime.utc_now()} [#{level}] #{message}"
  end
end

Configuration

# config/config.exs
config :arrea, :logger_formatter, MyApp.Logger

Summary

Callbacks

Formats a log message into a string.

Logs a message at the given level.

Returns the minimum log level this logger handles.

Types

level()

@type level() ::
  :debug | :info | :notice | :warning | :error | :critical | :alert | :emergency

metadata()

@type metadata() :: keyword()

Callbacks

format(level, t, metadata)

(optional)
@callback format(level(), String.t(), metadata()) :: String.t()

Formats a log message into a string.

Used by handlers that need a formatted string rather than direct output. The returned string should NOT include a trailing newline.

log(level, t, metadata)

@callback log(level(), String.t(), metadata()) :: :ok

Logs a message at the given level.

Called by the Arrea logging handler for each log event that passes the configured level threshold.

min_level()

(optional)
@callback min_level() :: level()

Returns the minimum log level this logger handles.

Events below this level will be silently dropped.