Structured JSON log formatter for production and staging environments.
Produces one JSON object per log line, compatible with Datadog, Loki, Google Cloud Logging, and other log aggregation pipelines.
Sample output
{"time":"2024-06-01T14:23:01.456Z","level":"info","msg":"[Aurinko] ← ok 42ms GET /email/messages","pid":"<0.234.0>","module":"Aurinko.HTTP.Client","request_id":"req-abc123"}Usage
Configure in prod.exs / staging.exs:
config :logger, :console,
format: {Aurinko.Logger.JSONFormatter, :format},
metadata: [:request_id, :module, :function, :line, :pid]
Summary
Types
@type log_timestamp() :: {{pos_integer(), 1..12, 1..31}, {0..23, 0..59, 0..59, 0..999}}
Functions
@spec format(Logger.level(), Logger.message(), log_timestamp(), keyword()) :: binary()