LogflareEx.LoggerBackend (logflare_ex v0.2.0-dev.1718053351.fca7edd)
Implements :gen_event behaviour, handles incoming Logger messages.
Usage
Add the following to your config.exs:
config :logger
backends: [..., LogflareEx.LoggerBackend]You can then log as per normal:
require Logger
Logger.info("some event", my: "data")Configuration
There are 3 levels of configuration available, and these are listed in priority order:
- Runtime Logger configuration, such as
Logger.configure(...) - Module level configuration via
config.exs, such asconfig :logflare_ex, Elixir.LogflareEx.LoggerBackend, source_token: ... - Application level configuration via
config.exs, such asconfig :logflare_ex, source_token: ...
Options will then be merged together, with each level overriding the previous.
Metadata
To add custom metadata, use Logger.metadata/1
Logger.metadata(some: "data")On the payload sent to Logflare API, the above metadata will be merged into the metadata field, resulting in the following schema path metadata.some.
Any additional Logger metadata provided in the Logger.info/2 call will be merged together by Logger.
This merging is not handled by the library.
This backend also enriches the log event with certaon fields:
metadata.context- context of the log event, including vm information, pid, module, etc.metadata.level- log level, corresponding to the Logger level set.metadata.stacktrace- stacktrace of the error, if the event is an error.
JSON-Encoding Conversions
To ensure that payload sent to Logflare API is JSON serializable and searchable by the selected backend, certain conversions are applied to the terms received.
- atoms are converted to strings.
For example,
:valueto"value". - charlists are converted to strings
For example,
'value'to"value". - tuples converted to lists
For example,
{1, 2}to[1, 2]. - keyword lists converted to maps
For example,
[my: :value]to%{"my"=> "value"}. - structs converted to maps
For example,
%MyStruct{}to%{some: "default key"}. - NaiveDateTime and DateTime are converted using the String.Chars protocol
For example,
%NaiveDateTime{}to1337-04-19 00:00:00. - pids are converted to strings
For example,
#PID<0.109.0>to"<0.109.0>"
Summary
Functions
Callback implementation for :gen_event.code_change/3.
Callback implementation for :gen_event.handle_call/2.
Callback implementation for :gen_event.handle_event/2.
Callback implementation for :gen_event.handle_info/2.
Callback implementation for :gen_event.init/1.
Callback implementation for :gen_event.terminate/2.
Types
level()
@type level() :: Logger.level()
log_msg()
message()
@type message() :: Logger.message()
metadata()
@type metadata() :: Logger.metadata()
Functions
code_change(old_vsn, config, extra)
Callback implementation for :gen_event.code_change/3.
handle_call(arg, config)
Callback implementation for :gen_event.handle_call/2.
handle_event(arg1, config)
@spec handle_event(log_msg(), Config.t()) :: {:ok, Config.t()}
Callback implementation for :gen_event.handle_event/2.
handle_info(arg1, state)
Callback implementation for :gen_event.handle_info/2.
init(_MODULE__)
@spec init(LogflareEx.LoggerBackend) :: {:ok, map()}
Callback implementation for :gen_event.init/1.
terminate(reason, state)
Callback implementation for :gen_event.terminate/2.