[slf4j-dev] [JIRA] (SLF4J-371) Support the lambda expression in the Logger
QOS.CH (JIRA)
noreply-jira at qos.ch
Fri Jun 21 00:17:02 CEST 2019
[ https://jira.qos.ch/browse/SLF4J-371?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=19654#comment-19654 ]
Dean Hiller commented on SLF4J-371:
-----------------------------------
@Robert @Federico @Eric the issue with 'build your own' which I did is that the call stack in development mode 'breaks'. ie. in our development server, we have slf4j log EVERY location(clickable in the IDE) using a special feature. If you build your own, you must configure for caller + 2 BUT THEN the 3rd party libraries log the wrong location. ie. we built our own and found out all 3rd party libraries were broken so we need to revert it all so the feature of clicking a log goes right to the log statement in Intellij and in Eclipse!!!
As an example, in Dev mode only as this has a 'performance cost'
2019-06-20 15:14:52,948 [-] [selectorThread] Caller+1 at org.webpieces.frontend2.impl.HttpServerImpl.lambda$0(HttpServerImpl.java:37)
INFO: now listening for incoming requests on /0:0:0:0:0:0:0:0:8080
we can click on HttpServerImpl.java:37 in the IDE and end up right at the log statement, but since this is with our wrapper, the 3rd party log statements log the wrong location/wrong line number :(.
This FEATURE ROCKS BTW. We use it on [https://github.com/deanhiller/webpieces]
I need to go back and revert all of the slf4j wrapper though :(....not fun.
Dean
> Support the lambda expression in the Logger
> -------------------------------------------
>
> Key: SLF4J-371
> URL: https://jira.qos.ch/browse/SLF4J-371
> Project: SLF4J
> Issue Type: Improvement
> Components: Core API
> Affects Versions: 1.7.22
> Reporter: MiNG
> Assignee: SLF4J developers list
> Fix For: 2.0
>
>
> In some cases, we don't want to calculate the expression for logging eagerly cause the performance reason. Then, we would write the code like the following:
> {code:java}
> if (LOGGER.isWarnEnabled())
> {
> LOGGER.warn("some message: {}", Json.serialize(obj));
> }{code}
> Before JDK8, there is no way to encapsulate the above code, because the expression is always calculated before passed as an argument. So, many "if"s appear in the code and smell badly.
> Now, the lambda expression is supported by JDK8, the above could be simplified like following:
> {code:java}
> LOGGER.warn(formatter -> formatter.format("some message: {}", Json.serialize(obj)));{code}
> With the default method definition in the org.slf4j.Logger:
> {code:java}
> public interface Logger
> {
> default void warn(Function<MessageFormatter, String> messageSupplier)
> {
> if (this.isWarnEnabled())
> {
> /* Calculate the expression only if the WARN level logging is enabled. */
> this.warn(messageSupplier.apply(this.getFormatter()));
> }
> }
> }{code}
--
This message was sent by Atlassian JIRA
(v7.3.1#73012)
More information about the slf4j-dev
mailing list