[ https://issues.apache.org/jira/browse/LOG4J2-599?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13964528#comment-13964528 ]
Gary Gregory commented on LOG4J2-599: ------------------------------------- Since {{Supplier}} is an interface, I can implement one to do whatever I want ;) like a useful toString() It's also a Java 8-only class. I see your point about passing in a bunch of Objects, once of them a supplier. But I think special casing {{Supplier}} is a mistake, at least for now. The issue is the same for Callable of course. I could see adding logger.debug(Callable<?>), a one arg method or maybe also logger.debug(String, Callable...) where you can pass in one or more Callables. You could then argue the same for Supplier, Future and who knows what else executable objects that return a value. Today I can say: {code:java} if (logger.isDebugEnabled()) { logger.debug("I am expensive to compute {}", this.iAmExpensive(); } {code} It sure would be nice to remove that with a one liner, but without Java 8, it's worse! {code:java} logger.debug("I am expensive to compute {}", new Callable<Object>() { @Override public Object call() throws Exception { return this.iAmExpensive(); } } ); {code} Since we are on Java 6, should we table this discussion? ;) > 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: log4j-dev-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-dev-h...@logging.apache.org