xadhoom

xadhoom

Logbook - a tag/category based logger

I’ve published to hex Logbook, our Logger wrapper that’we use on a couple of rather big projects. Has been around since early 2019, but just now added to hex.pm

GitHub Repo: GitHub - VoiSmart/logbook: Another opinionated logger for Elixir, with the addition of tag/module based logging. · GitHub
Docs: Logbook — logbook v4.0.0
Hex.pm: logbook | Hex

Basically is a Logger wrapper that adds categories (or tags) to each logger entry, and each tag can have it’s own log level. As a bonus, module names are automatically tracked as tags and a specific log level can be set for them, too.

Intended usage: activate a specific log level for a specific module only, or a specific log level for a tag (or a group of tags) that may spread across different modules.

By design, the “global” Elixir Logger level still wins: you cannot activate a debug level for a tag and have it emitted if the global Logger level is higher (set on :error for example). But if all the codebase uses Logbook instead of Logger this is not really a problem.

We built it because on our large application, we have different subsystems running, and just enabling a more verbose logger level is a no-go, since too many logs are emitted and is difficult to follow what is going on (or puts too much pressure on the Logger reducing overall performances). With Logbook we can nail down what we want to see and investigate more freely.

The library is pretty solid, is running in production on several systems since the beginning.

First 2 of 2 Posts Switch mode

hauleth

hauleth

Since Elixir 1.10 you can do it on per-module basis via:

:logger.set_module_level(Mod, level)

And since 1.11 it is also exposed via Logger API as:

Logger.put_module_level(Mod, level)

There are also 2 “meta levels” :all and :none. Their behaviour should be rather obvious.

Also similar thing can be achieved via setting :domain in metadata and then using :logger.add_primary_filter/2.

xadhoom

xadhoom OP

Thanks! This was done before 1.10 so was needed. But I think now we can leverage on the official APIs for the module level part.

Well, like above we started with v1.9. But still, having to dynamically filter based on the :domains (currently we keep track of that on a ETS table) means doing something similar to what we already do (attach/remove a filter on the fly). Still, I’m not sure if the :domains means the sames as tags, I see tags more specific inside a domain.

Said that, since we now require Elixir v1.11+ in Logbook v2, I think something can be adapted to use the official APIs, especially for the module parts.

thanks for pointers!

— All posts loaded —

Where Next?

Trending in Announcing Top

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...
387 14960 120
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
shahryarjb
The Chelekom project is a library of Phoenix and LiveView components generated via Mix tasks to fit developer needs seamlessly. One of i...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New

Other Trending Topics Top

type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New
bjorng
We want to introduce a new native datatype to Erlang: native records. Although replacing all tuple records with native records is not our...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
alexslade
Fly’s CEO posted this recently - Turn And Face The Strange · The Fly Blog It says that Fly is going all-in on sprites, which is a worry ...
New

We're in Beta

About us Mission Statement