LoggerHumioBackend

About

A Elixir Logger backend for Humio.

Supported options

Required

Optional

Using it with Mix

To use it in your Mix projects, first add it as a dependency:

def deps do
[{:logger_humio_backend, "~> 0.2.0"}]
end

Then run mix deps.get to install it.

Configuration Examples

Runtime

Logger.add_backend {Logger.Backend.Humio, :debug}
Logger.configure {Logger.Backend.Humio, :debug},
format: "[$level] $message\n"
host: "https://humio-ingest.bigcorp.com:443",
level: :debug,
token: "ingest-token-goes-here",

Application config

Minimal

config :logger,
utc_log: true #recommended
backends: [{Logger.Backend.Humio, :humio_log}, :console]
config :logger, :humio_log,
host: "https://humio-ingest.bigcorp.com:443/",
token: "ingest-token-goes-here",

With All Options

config :logger,
utc_log: true #recommended
backends: [{Logger.Backend.Humio, :humio_log}, :console]
config :logger, :humio_log,
host: "https://humio-ingest.bigcorp.com:443/",
token: "ingest-token-goes-here",
format: "[$level] $message\n",
level: :debug,
metadata: [:request_id, :customer_id],
max_batch_size: 50,
flush_interval_ms: 5_000,
debug_io_device: :stderr,
fields: %{
"service" => "my_service"
},
tags: %{
"env" => "dev"
}

Tesla

The default (and currently only) client. Compresses payload using gzip and contains sensible retry defaults.

Batching

The library will batch requests until either

  1. the buffer of logs has reached the max_batch_size or
  2. an amount of time equal to flush_interval_ms has passed.

At this point the logger backend will send all accrued log events to Humio, and reset the flush interval timer.

The logger can be flushed manually by calling Logger.flush(). Note this will flush all registered logger backends.

Metadata

Metadata is sent to Humio as attributes using the Structured Ingest API. This means any metadata you set will be ingested as fields in Humio, and, unlike the :console logger, metadata can not be appended in the Formatter. This is much more powerful than the :console logger, as it enables the ingestion of nested maps, lists, and generally more complex metadata than just string values.

Formatter

This logging backend implements its own formatter, similar to Elixir's Logger.Formatter.

It allows developers to specify a string that serves as template for log messages, for example:

$hostname[$pid]: [$level]$levelpad $message

Will print error messages as:

localhost[<0.349.0>]: [error] Hello

The valid parameters you can use are: