[
https://issues.apache.org/jira/browse/LOG4J2-599?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13964547#comment-13964547
]
Nick Williams commented on LOG4J2-599:
--------------------------------------
I would disagree with the notion that we are "on Java 6." We're not _on_
anything. We _compile for_ Java 6—an end-of-life product with severe, unfixed
security vulnerabilities (such as the new Heartbleed vulnerability)—so that we
can provide backwards compatibility for people who shouldn't be using Java 6
anymore. That should in no way prevent us from providing tools that help those
using more modern JVMs. :-)
I suppose an alternative API for {{Callable}} could be:
{code:java}void ***(String message, Callable<Object[]> arguments);{code}
In Java 8, this would be fairly easy to use for simple and expensive arguments:
{code:java}logger.trace("Enter {} {} {} {}", (Callable)() -> new Object[] {
argument1, argument2, argument3.someMethod(), argument4});{code}
However, we couldn't do the same thing for {{Supplier}} unless we compiled in
Java 8. The only way to support {{Supplier}} and maintain backwards
compatibility with Java 6 and 7 is to support it with {{Object...}}.
> Support lambda functions (or similar) for log message parameters
> ----------------------------------------------------------------
>
> Key: LOG4J2-599
> URL: https://issues.apache.org/jira/browse/LOG4J2-599
> Project: Log4j 2
> Issue Type: Brainstorming
> Components: Core
> Reporter: Matt Sicker
> Priority: Minor
>
> It would be nice if we could support 0-param lambda functions (or the
> equivalent: interfaces with a single empty-parameter message call), or more
> simply, allow Runnables (or something similar) to be passed which will be
> dynamically executed if the log message is enabled.
> The use case here is that although string construction of the log message is
> a performance issue that is already solved quite well, the problem of adding
> in information to the log message that makes other calculations still needs
> to be wrapped in an if check.
> I'm not sure if it'd be best to just use Runnable, or create a new interface,
> or try to emulate how Java 1.8 lambdas work via an interface with a single
> method defined. The details here would still need to be fleshed out, but I
> think this sort of feature could be rather handy (especially in a Java 1.8+
> environment, or in Groovy/Scala/etc.).
--
This message was sent by Atlassian JIRA
(v6.2#6252)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]