AntlUtilsElixir.ReqApiLogger (antl_utils_elixir v1.6.8)

Req Logging plugin tailored for API clients

Link to this section Summary

Functions

Installs request, response, and error steps that log API calls

Link to this section Functions

Link to this function

attach(req, opts \\ [])

Installs request, response, and error steps that log API calls

Options

  • :api_name (mandatory) - name of the api; will be available to the app as metadata
  • :log_level (default :info) - level at which then logging is done
  • :hide_request_keys (default []) - list of request keys that should be hidden (for json or form requests)
  • :hide_response_keys (default []) - list of response keys that should be hidden (for json responses)
  • :hide_request_headers (default []) - list of request headers that should be hidden
  • :hide_response_headers (default []) - list of response headers (and trailers) that should be hidden

These same options can also be passed through Req options to change the behavior on a per-request basis.

Examples

By default, log requests, responses and errors at level :debug with name "my_api" in metadata

req = Req.new() |> ReqApiLogger.attach(api_name: "my_api", log_level: :debug)

# send request, log with options passed to attach/1
Req.get!(req, url: "https://example.org")

# on this request only, log at level :warning, while hiding keys from the request query and response headers
Req.get!(req,
  json: %{login: "foo", password: "bar"}
  url: "https://example.org",
  log_level: :warning,
  hide_request_keys: ["password"],
  hide_response_headers: ["x-private-header"]
)