Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lambda support for SLF4J API

In Log4j latest API we have Lambda support where I can manage the Debug option easily.

Example:

logger.debug("This {} and {} with {} ",    () -> this, () -> that, () -> compute()); 

But for slf4j/logback is there any option to have lambda enabled as mentioned above. Please let me know the syntax then.

like image 721
Souvik Avatar asked Dec 21 '16 05:12

Souvik


2 Answers

Unfortunately, this is not supported yet: https://jira.qos.ch/browse/SLF4J-371

like image 72
Mariano Ruiz Avatar answered Sep 22 '22 06:09

Mariano Ruiz


SLF4J – version 2

Version 2 of SLF4J has support for lambda syntax.

This new version also brings a fluent API. Version 2 requires Java 8 or later.

As of 2020-06, version 2 is still in the experimental/unstable phase, with the most recent alpha release being from 2019-10.

Maven POM setting:

<dependency>     <groupId>org.slf4j</groupId>     <artifactId>slf4j-api</artifactId>     <version>2.0.0-alpha1</version> </dependency> 

See the Download page.

like image 24
Basil Bourque Avatar answered Sep 21 '22 06:09

Basil Bourque