
[](https://hex.pm/packages/svadilfari/)
[](https://hexdocs.pm/svadilfari/)

[](https://coveralls.io/github/akasprzok/svadilfari?branch=main)
# 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`:
```elixir
def deps do
[
{:svadilfari, "~> 0.1"}
]
end
```
Configure some parameters:
```elixir
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](https://hexdocs.pm/logger/1.13.4/Logger.Backends.Console.html#module-options):
* `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](https://hexdocs.pm/sleipnir/readme.html#customizing-the-client) args can be passed here.