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
Docs: Logbook — logbook v2.0.1
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.


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.


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!

1 Like