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 GitHub - ferd/flatlog: A custom formatter for the Erlang logger application that turns maps into single line text logs · GitHub – 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 Announcing Top

mischov
import Meeseeks.CSS html = HTTPoison.get!("https://news.ycombinator.com/").body for story <- Meeseeks.all(html, css("tr.athing")) do...
New
restlessronin
The repo is at GitHub - cyberchitta/openai_ex: Community maintained Elixir library for OpenAI API · GitHub. Docs are at OpenaiEx User Gu...
152 10167 134
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...
384 13736 119
New
Eiji
ExApi is a library that I’m developing now and hope release soon This library will allow to: list all apis list all api implementation...
New
woutdp
Hi! I wanted to introduce my latest project LiveSvelte. It allows you to render Svelte inside LiveView with end-to-end reactivity. It’s ...
New
oltarasenko
Dear Elixir community, After a year of development, bug fixes, and improvements, we are proudly ready to share the release of Crawly 0.1...
New
MRdotB
I needed to reuse React components from my Chrome extension in my Phoenix/LiveView backend. I noticed that for Svelte/Vue, there are live...
New
Azolo
Hey everyone, I just released WebSockex which is a Elixir WebSocket client. WebSockex strives to work as a OTP special process, be RFC6...
New
michalmuskala
Another small library today. PersistentEts Hex: persistent_ets | Hex GitHub: GitHub - michalmuskala/persistent_ets · GitHub Ets table ...
New
woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New

Other popular topics Top

sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement