Svadilfari
A logger backend for sending logs directly to Grafana Loki.
Installation
The package can be installed by adding svadilfari
to your list of dependencies in mix.exs
:
def deps do
[
{:svadilfari, "~> 0.1.1"}
]
end
Configure some parameters:
config :logger, :backends, [:console, Svadilfari]
config :logger, :svadilfari,
metadata: [:user_id, :bogons],
max_buffer: 10,
client: [
url: "http://localhost:3100",
opts: [
org_id: "tenant1"
]
],
labels: [
{"service", "svadilfari"},
{"env", "dev"}
]
and start sending logs to Loki!
Configuration
A majority of configuration values works just like the :console
logger, and more in-depth information on their function can be found here:
-
level
: The log level. -
format
: The format message used to print logs. Defaults to"\n$time $metadata[$level] $levelpad$message\n"
. -
metadata
: The metadata to be printed by$metadata
. -
max_buffer
: Maximum events to buffer while waiting for Loki to respond. Defaults to 32. Once full, the backend will block until Loki returns a success or error.
There are a few Loki-specific parameters:
-
labels
: A list of{String.t(), String.t()}
tuples that represents Loki labels. -
client
:-
url
: The Loki URL to send to. The/loki/api/v1/push
path is inferred. -
opts
: Svadilfari uses the Sleipnir Loki client under the hood. Sleipnir Tesla Client args can be passed here.
-