bettio

bettio

Pretty_log: logfmt (and other formats) Logger formatter

Here in Ispirata we develop Astarte, an Elixir IoT/data processing platform. Astarte is made of several microservices which produce a massive amount of logs.

Recently we decided to start using logfmt as logs format, which is a human (and machine) readable structured log format, that makes queries, filtering and analysis easy while keeping log lines clear for humans.
Last but not least it avoids bikeshedding about how to format log lines, so developers are free to spend their time bikeshedding on more interesting topics.

To achieve this goal we’ve created pretty_log Elixir Logger formatter library, which takes care of formatting log (without the need of changing logger backend).

pretty_log is metadata centric, so it encourages use of Logger.metadata to keep track of all relevant information.
We also created a replacement plug for Plug.Logger (plug_logger_with_meta
) which logs requests with all relevant metadata.

This is how log lines look like when using both pretty_log and plug_logger_with_meta:

level=info ts=2019-10-28T16:57:41.087+01:00 msg="Got client request." method=GET request_path=/v1/autotestrealm/interfaces module=PlugMetadataLogger function=call/2 request_id=FdHav4gx9ruV1-QAACZi tag=got_client_req
level=info ts=2019-10-28T16:57:41.110+01:00 msg="Sent reply." status_code=200 elapsed=22ms realm=autotestrealm module=PlugMetadataLogger function=call/2 request_id=FdHav4gx9ruV1-QAACZi tag=sent_reply

Hope you’ll find this useful :slight_smile:
Let me know if you have any request/question/feedback.

Most Liked

tristan

tristan

Rebar3 Core Team

Nice.

And for those looking for similar for Erlang’s logger there is https://github.com/ferd/flatlog – not sure if this can work with Elixir yet… I believe you can use logger as the backend for Logger now but not sure the metadata works.

Where Next?

Popular in Libraries Top

deadtrickster
I’ve just released stable versions of my Prometheus Elixir libs: Elixir client [docs]; Ecto collector [docs]; Plugs instrumenter/Export...
New
praveenperera
FastRSS Parse RSS feeds very quickly: This is rust NIF built using rustler Uses the RSS rust crate to do the actual RSS parsing Speed...
New
arkgil
Hi all! I’m happy to announce that Telemetry v0.3.0 is out! This release marks the conversion from Elixir to Erlang so that all the libr...
New
michalmuskala
Another small library today. PersistentEts Hex: persistent_ets | Hex GitHub: GitHub - michalmuskala/persistent_ets Ets table backed by...
New
wfgilman
I’ve cleaned up and open sourced three financial libraries I was using for my company. They are bindings for the APIs of these three comp...
New
asiniy
Hey there! I wrote a download elixir package which does exactly what its name about - an easy way to download files. I saw solutions ...
New
woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
tmbb
PhoenixWS - Websockets over Phoenix Channels Source code on Github here: https://github.com/tmbb/phoenix_ws Phoenix channels are a great...
New
maltoe
Hello! Came here to announce ChromicPDF, a pet project PDF generator I’ve been working on for the past few months. Why another PDF gener...
New
bluzky
You may know https://ui.shadcn.com/, a UI component library for React. I really love it’s design style and components. I’ve built some co...
381 12391 119
New

Other popular topics Top

lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

Sub Categories:

We're in Beta

About us Mission Statement