Overload logger methods to allow single/multiple lambda parameters to be used in garbage-free mode #1936
Replies: 1 comment 1 reply
-
The issue is the number of combinations. While you show a method with all Suppliers once you go beyond one you will be asked to support both Suppliers and Objects for any one parameter. This makes the number of methods huge, and we already have a ton. To be honest, a better approach is to use LogBuilder and do something like: |
Beta Was this translation helpful? Give feedback.
-
Quoting from Log4J2 Garbage-free Steady State Logging page:
From my (user) perspective, I knowingly choose lazy logging method to log a
callExpensiveMethod()
. One of the lazy-logging method that is convenient to use is using lambda as logging parameter, e.g.logger.debug("Large data is {}", () -> callExpensiveMethod())
.But it seems unintuitively not recommended to use in garbage free mode.
If the reason is that it creates vararg array, why not overload the method to allow static number of parameters just like the classic method:
So there could be a version for lambda parameters like this:
What makes it not an option in Log4J2?
Beta Was this translation helpful? Give feedback.
All reactions