I have a Spring application that uses @slf4j annotation from Lombok, but everything I log with it is not shown in the console.
My application includes the following library slf4j-api-1.7.21 jcl-over-slf4j-1.7.21 lombok-1.16.10
Everything I log is being passed to NOPLogger (No Operation logger) that does exactly what it's supposed to do... nothing!
Do I need to configure a factory somewhere in order to use a logger that will actually log something?
Annotation Type Slf4jCauses lombok to generate a logger field. Complete documentation is found at the project lombok features page for lombok log annotations. This annotation is valid for classes and enumerations.
This is the main purpose of SLF4J (Simple Logging Facade for Java) – a logging abstraction which helps to decouple your application from the underlying logger by allowing it to be plugged in – at runtime. Of course, the flexibility that such an abstraction provides is the main reason to use SLF4J.
@Slf4j – Creates the logger with following statement: Creates private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(LogExample.
Unlike log4j, SLF4J (Simple Logging Facade for Java) is not an implementation of logging framework, it is an abstraction for all those logging frameworks in Java similar to log4J. Therefore, you cannot compare both.
I figured, adding slf4j-api is not enough, you also need a proper implementation of the APi.
Adding this will work:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.21</version>
</dependency>
If you are importing @slf4j with Lombok, then you need 3 dependencies in your pom.xml file.
As @pmartin8 indicated, you need to add slf4j-simple
, but all three required dependencies will look like this:
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.26</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.21</version>
</dependency>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With