First of all I will give a brief explanation about the scenario. In my application I am using SLF4J as the logging facade. For logging, I am using Log4j2 and I have my customized log4j2.xml
as well.
When I log in my classes, I create a logger as mentioned below:
private static final Logger LOG = LogManager.getLogger(TestController.class);
Later, I found out that there is a @Slf4j
annotation and then I can log without creating a logger instance manually.
log.info("Info log in getHello() in TestController");
I did a minor research about the topic where is there any drawbacks of using @Slf4j
annotation, instead of creating a logger instance within the class. I did not come across any reason why shouldn't use @Slf4j
annotation.
However, before proceeding I wanted to ask from this community to confirm is there any drawback of using @Slf4j
?
Annotation Type Slf4j Causes 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.
@Slf4j – Creates the logger with following statement: Creates private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(LogExample.
Lombok is a build-time only dependency; there is no need for lombok. jar to be available when your application is run, it just needs to be there when you compile your code. Therefore, lombok is highly unlikely to be a source of security vulnerabilities.
Lombok's @Slf4j generates a logger instance with default name log using the SLF4J API.
From the documentation of @Log
and friends:
...
@Slf4j
Creates
private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(LogExample.class);
...
We see that this is equivalent to
private static final Logger LOG = LogManager.getLogger(TestController.class);
aside from the name of the field.
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