Logging From ElixirBETA

This feature requires AppSignal for Elixir version 2.6.0 or higher.

This documentation outlines how to configure logging with the AppSignal for Elixir integration.

Shell
mix deps.update appsignal

Configure Logging

Your log data must not contain any personal data, such as names, email addresses, etc. It is your responsibility to ensure this data is filtered out before being sent to AppSignal, and when identifying a person is necessary that your application uses alternative forms of identification such as a user ID, hash, or pseudonym.

You do not need to create a log source to send logs from the AppSignal for Elixir integration. An "application" log source will be created automatically.

Logger Backend

Starting with Elixir version 1.15, Elixir logger backends are no longer recommended. See the Logger Handler section below for the recommended alternative.

You can configure the Elixir Logger to use the Appsignal.Logger.Backend module as a backend by placing the code below in the config/runtime.exs file:

Elixir
config :logger, backends: [:console, {Appsignal.Logger.Backend, [group: "phoenix"]}]

The group attribute describes where you are logging from and can be used in AppSignal to filter your logs. Note that you need to add the :console shortcut for the default console logger if you also want your logs to be printed to the console.

You can also add the backend using the add_backend/2 function on your Application.start/2 callback:

Elixir
@impl true def start(_type, _args) do Logger.add_backend(Appsignal.Logger.Backend, group: "phoenix")

Logger Handler

This feature requires AppSignal for Elixir version 2.7.10 or higher.
This feature requires Elixir version 1.15+ or higher.

Instead of using an Elixir logger backend, you can configure the Erlang :logger to use the Appsignal.Logger.Handler module as a handler, by calling the Appsignal.Logger.Handler.add/2 function on your Application.start/2 callback:

Elixir
@impl true def start(_type, _args) do Appsignal.Logger.Handler.add("phoenix")

Elixir Logger

To send logs to AppSignal without using the Elixir Logger backend, you can use one of Appsignal.Logger's logging functions and provide it with a groupname that defines where you are logging from. For example, if we were logging from a helper for invoicing clients:

Elixir
Appsignal.Logger.info("invoice_helper", "Generating invoice for customer 129")

Usage

Sending Logs

Like the Elixir/Phoenix logger class, you can define the severity level of your logs by using fatal, error, warning, info, and debug:

Elixir
Appsignal.Logger.warning("app", "Something's gone terribly wrong here")

You can define custom attributes to send log information that can be used when filtering and querying logs:

Elixir
Appsignal.Logger.info("invoice_helper", "Generated invoice for customer #{customer.id}", %{ customer_id: customer.id, invoice_id: invoice.id})

You can query and filter on message contents and attribute values from within the Log Management tool.

Once configured, the desired attributes will be sent to AppSignal as log_tags, and be queryable in the AppSignal logging interface.

Logfmt

The AppSignal Logger can also parse attributes out of a Logfmt-formatted line. To do so, pass :logfmt as the second argument:

Elixir
Appsignal.Logger.info("invoice_helper", "Generated invoice invoice_id=A145 for customer customer_id=123")

JSON

The AppSignal Logger can also parse attributes out of a JSON-formatted line. To do so, pass :json as the second argument:

Elixir
Appsignal.Logger.info("invoice_helper", ~s({"message": "Generated invoice for customer", "invoice_id": "A145", "customer_id": "123"}))

Only primitive non-nested values (numbers, strings, booleans and null) will be shown as log attributes. All other attributes will be discarded.

Filtering Logs

You can use the ignore_logs configuration option to ignore log lines based on their message. See our Ignore Logs guide to learn more.

Need Help?

After configuring your Elixir application to send logs, logs should appear in AppSignal. If you are unsure about this step or AppSignal is not receiving any logs, you can always reach out for assistance. We'll help get you back on track!