LoggerLokiBackend

LoggerLokiBackend is an Elixir logger backend providing support for Logging directly to Grafana Loki

Hex.pm Version

It is a fork of LokiLogger that was updated to use Loki’s new push API.

Also, the main intended usage of this is for development environment, where I normally run Loki inside a docker container but my application runs on my machine, which make hard to implement a solution to get the logs from my application into Loki, hence I won’t be focusing right now on production-grade performance.

Known issues

Features (and TODO)

Installation

The package can be installed by adding logger_loki_backend to your list of dependencies in mix.exs:

def deps do
  [
    {:logger_loki_backend, "~> 0.3.0"}
  ]
end

Configuration

Elixir Project

Loki Logger’s behavior is controlled using the application configuration environment:

For example, the following config/config.exs file sets up Loki Logger using level debug, with application label logger_loki_backend_library.

use Mix.Config

config :logger,
       backends: [LoggerLokiBackend]

config :logger, :logger_loki_backend,
       level: :debug,
       format: "$metadata level=$level $message",
       metadata: :all,
       max_buffer: 300,
       loki_labels: %{application: "logger_loki_backend_library", elixir_node: node()},
       loki_host: "http://localhost:3100"

Protobuff lib regeneration

only needed for development

shell script protoc --proto_path=./lib/proto --elixir_out=./lib/proto lib/proto/push.proto

License

LoggerLokiBackend is a fork of LokiLogger, which was licensed under Apache v2.0 License and copyrighted to Ward Bekker.

Existing unmodified code still retains the same license, but new code is copyright of Bernardo Amorim, also released under Apache v2.0 License.

Check LICENSE for more information.