You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by "Jason Tovey (JIRA)" <ji...@apache.org> on 2015/03/11 19:44:39 UTC

[jira] [Comment Edited] (LOG4J2-599) Support lambda functions (or similar) for log message parameters

    [ https://issues.apache.org/jira/browse/LOG4J2-599?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14357373#comment-14357373 ] 

Jason Tovey edited comment on LOG4J2-599 at 3/11/15 6:44 PM:
-------------------------------------------------------------

The lambda expression for a ```Supplier<String>``` would be the same as ```Callable<String>```:
````() -> "Here is my log message."````

So from a Java 8 user's point of view, I'd be perfectly happy if log4j2 supported methods such as
```debug(Callable<String>, Throwable)```.  Since Callable has been around since 1.5 you don't have anything to worry about.

Just make sure to pass the Callable as-is until you've decided that it's getting written to an Appender, then ```.call()``` it.


was (Author: jasontovey):
The lambda expression for a ```Supplier<String>``` would be the same as ```Callable<String>```:
```() -> "Here is my log message."```

So from a Java 8 user's point of view, I'd be perfectly happy if log4j2 supported methods such as
```debug(Callable<String>, Throwable)```.  Since Callable has been around since 1.5 you don't have anything to worry about.

Just make sure to pass the Callable as-is until you've decided that it's getting written to an Appender, then ```.call()``` it.

> 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: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org