Logging with Project Lombok

Normally, when we use a Logging framework like Log4J, Logback or Simple Logging Facade for Java (SLF4J) for these Logging frameworks in a class, we need declare for example as below:

But with Project Lombok, we don’t need to do that.

When using Project Lombok, we only need declare an annotation for using a Logging framework, then we can use this Logging framework as usual. For example, I can declare @Slf4j annotation for using Simple Logging Facade for Java in my example as below:

In this case, if you check the /target/classes/com/huongdanjava/lombok/Example.class, you will see the content of Example class as below:

Obviously, you can see Project Lombok will generate the code to declare Logger object in class Example automatically.

Below is some others annotation for other Logging frameworks:

One thought on “Logging with Project Lombok

  1. Is there any way to change Logging level based on User:

    Ex:
    log.setLevel(Level.WARN)

    currently not supporting

Add Comment