PrettyLog

PrettyLog is an Elixir library which provides some ready-to-use log formatters, including a Logfmt formatter.

Installation

def deps do
  [
    {:pretty_log, "~> 0.1"}
  ]
end

Using PrettyLog

Just change the :format config entry in your config/{prod,dev,test}.exs files:

-config :logger, :console, format: "[$level] $message\n"
+config :logger, :console,
+  format: {PrettyLog.LogfmtFormatter, :format},
+  metadata: [:module, :request_id, :tag]

metadata is arbitrary and optional.

You may change the default key names via the following config options, values must be atoms:

config :pretty_log,
  :timestamp_key_name, :when, # defaults to :ts
  :level_key_name, :severity, # defaults to :level
  :message_key_name, :humans, # defaults to :msg

Available Formatters

Following formatters are included:

Formatter Vs Backend

Formatter and logger backend are two distinct components.

This library is focused on logs formatting, leaving to you the choice about your favourite backend.

About This Project

This project has been created in order to provide better logs in Astarte. We are open to any contribution and we encourage adoption of this library, also outside Astarte, in order to provide better logs to everyone.