In Lombok, @Slf4j is a class-level annotation that generates a private static final SLF4J Logger field named log during compilation. You write @Slf4j, then call log.info(...) or log.error(...) without declaring or initialising the logger. It is one of several Lombok logging annotations and targets the SLF4J facade, which delegates to Logback, Log4j2 or another backend.
Lombok is an annotation processor. During compilation it modifies the syntax tree of your class and inserts a field, so the compiled class file contains exactly this:
There is no reflection, proxy or runtime dependency on Lombok. You can verify it with javap -p PaymentService.class or by running the delombok tool, which writes the expanded source.
If you run this with slf4j-api and Logback on the classpath, the failed charge prints a line at ERROR level followed by the stack trace. Without any backend, SLF4J 2.x prints a warning that no provider was found and discards the output, so always add a backend such as logback-classic.
Replace the version properties with the current releases from Maven Central. Spring Boot users can omit versions because the Boot BOM manages them. On JDK 23 and later, list Lombok in the compiler plugin's annotationProcessorPaths, since javac no longer discovers processors from the classpath by default.
log, which removes copy-paste mistakes such as a logger created for the wrong class.| Setting | Where | Result |
|---|---|---|
@Slf4j(topic = "audit") | Annotation | Logger named audit instead of the class |
lombok.log.fieldName | lombok.config | Renames log project-wide |
lombok.log.fieldIsStatic | lombok.config | Makes the field an instance field when set to false |
lombok.log.custom.declaration | lombok.config | Declares a custom logger type |
A lombok.config file at the project root applies to its directory tree:
| Annotation | Logger type |
|---|---|
@Slf4j | org.slf4j.Logger |
@Log4j2 | Log4j 2 Logger |
@Log | java.util.logging.Logger |
@CommonsLog | Apache Commons Logging Log |
@XSlf4j | SLF4J extended logger |
@Flogger | Google Flogger |
Pick the one that matches your logging API. For most modern projects that is @Slf4j.
log gets a Lombok warning and no generated field.log in the editor. Compilation by Maven or Gradle works either way when the annotation processor is configured.SLF4J is the Simple Logging Facade for Java, an API in front of logging frameworks. @Slf4j is Lombok's annotation that creates an SLF4J logger.
Yes. Lombok only generates code that refers to org.slf4j.Logger, so the SLF4J API must be on the compile classpath.
Yes, set lombok.log.fieldName in lombok.config.
Run delombok or inspect the compiled class with javap -p.
@Slf4j makes Lombok insert a static final SLF4J logger named log at compile time. It cuts boilerplate, keeps logger naming consistent and has no runtime cost. Add the SLF4J API and a backend, configure the annotation processor on newer JDKs, and log with placeholders.