[
https://issues.apache.org/jira/browse/LOG4J2-599?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14662848#comment-14662848
]
Remko Popma commented on LOG4J2-599:
------------------------------------
I would not mind using Logger2 as a more generic name.
I like Jukka's idea to provide a custom functional interface that supplies
Message objects to support lambda expressions that create custom Messages.
Ralph, using {{Callable}} to support lambda expressions is perfectly fine and
not unconventional. Java 8 accepts any interface that has a single abstract
method as a functional interface. The {{java.util.function}} interfaces are
there to make it easier for people to write lambda-enabled code, but there is
no requirement to use only these interfaces. The java.util.function package
documentation gives FileFilter as an example of an existing interface that can
be used to support lambdas. There is certainly no need to add methods for
Supplier, Function, Predicate or any of the other many functional interfaces
defined in java 8. The goal is to support client code that looks like
{{logger.debug(() -> someMethod());}}, not {{logger.debug(new
Supplier<String>() \{ return someMethod(); \});}}
You have a good point that our log4j-jul module currently only supports the
Java 6/7 java.util.logging API, it does not support the Java 8
java.util.logging API. If we want to support this we should perhaps create a
log4j-jul8 module, not sure if we can achieve this with reflection...
> 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
> Labels: Java8
>
> 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.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]