PrettyLog is an Elixir library which provides some ready-to-use log formatters, including a Logfmt formatter.
- Add
:pretty_log
dependency to your project'smix.exs
:
def deps do
[
{:pretty_log, "~> 0.1"}
]
end
- Run
mix deps.get
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
Following formatters are included:
- PrettyLog.LogfmtFormatter
- PrettyLog.UserFriendlyFormatter
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.
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.