A built-in telemetry handler that logs FRED API request details using Elixir's Logger.
Attach it in your application's start/2 callback for quick observability:
def start(_type, _args) do
Fred.Telemetry.Logger.attach()
# ...
endOutput
On every completed request (:stop event) it logs at the configured level:
[fred] GET /series/observations - 200 in 142ms (params: [series_id: "UNRATE", frequency: :m])On errors:
[fred] GET /series/observations - error in 83ms: (400) Bad Request (params: [series_id: ""])On exceptions (:exception event):
[fred] GET /series/observations - exception in 5012ms: %Req.TransportError{reason: :timeout}Configuration
Pass options to attach/1 to customize behavior:
Fred.Telemetry.Logger.attach(
level: :info, # Logger level (default: :info)
handler_id: "my-fred-log" # Unique handler ID (default: "fred-default-logger")
)Detaching
To stop logging, detach by handler ID:
Fred.Telemetry.Logger.detach()
# or with a custom ID:
Fred.Telemetry.Logger.detach("my-fred-log")
Summary
Functions
@spec attach(keyword()) :: :ok | {:error, :already_exists}
Attaches the logger handler to FRED telemetry events.
Options
:level- TheLoggerlevel to log at. Default::info:handler_id- A unique string ID for this handler. Default:"fred-default-logger". Useful if you want to attach multiple loggers with different configs.
Returns :ok or {:error, :already_exists} if the handler ID is taken.
@spec detach(String.t()) :: :ok | {:error, :not_found}
Detaches the logger handler.
Parameters
handler_id- The handler ID to detach. Default:"fred-default-logger"