Skip to content

secomind/pretty_log

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PrettyLog

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

Installation

  • Add :pretty_log dependency to your project's mix.exs:
def deps do
  [
    {:pretty_log, "~> 0.1"}
  ]
end
  • Run mix deps.get

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:

  • PrettyLog.LogfmtFormatter
  • PrettyLog.UserFriendlyFormatter

Formatter Vs Backend

Formatter and logger backend are two distinct components.

  • The formatter transforms a log message and its metadata into a binary
  • The logger backend outputs log binaries

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.