Hello everybody,
Elixir's logger is a solid library, it has one awkwardness in use, though. When logging data that might be expensive to produce (and arguably anything besides static strings is expensive to produce for logging), logger requires wrapping the content in a function.
This is dictated by the fact that otherwise logger can't guarantee the argument to the logger macros will be evaluated, so it has to be explicitly marked as lazy. Unfortunately, while this solution is correct, it is quite awkward to use and makes the code less readable.
I propose adding a new Logger.Lazy module with the same interface as the Logger module - and by that I mean all the debug, info, warn and error macros. The only difference would be in the fact that macros from that module, wouldn't give guarantee as to the execution of the argument of the log macros. This could be achieved by implicitly wrapping in a function or probably (and preferably) injecting the test condition directly into the call site.
Introduction of a new module makes it extremely easy to use in new code (without needing to learn anything new or exploring new interfaces) and adding a separate module makes it possible to update old code extremely easily - all that's needed is change the line
require Logger
into
require Logger.Lazy, as: Logger