I want to use logger from Lombok. I added @Slf4j
annotation, added dependency and it says that it cannot resolve symbol log
. Error:(5, 1) java: package org.slf4j does not exist
package a;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class a {
public static void main(String[] args) {
log.info("lala");
}
}
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>a</groupId>
<artifactId>a</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.8</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
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.
Lombok's @Slf4j generates a logger instance with default name log using the SLF4J API. Note that we must also include a library that implements the Slf4j API.
You also need to add slf4j itself as a dependency to your project by including it in your pom file. All lombok features in the lombok.extern
package share this property: They help you use a library that is NOT already available out of the box as part of java itself, and for all of them, lombok does not inherently include any of these dependencies.
Should be as simple as adding the following block to your pom.xml
:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.26</version>
</dependency>
I tried adding slf4j-api as a dependency as rzwitserloot suggested above, but that did not work for me. Adding it as a plugin in my build.gradle file did, though:
plugins {
...
id 'io.freefair.lombok' version '4.1.6'
...
}
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