Add dependencies in the pom.xml of the MAVEN project:
<dependency>
<groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.5< /version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.7.5 </version>
</dependency>
<dependency>
<groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</ Version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version> 1.16.18</version> <scope>provided</scope>
</dependency>
- SLF4J is a collection of interfaces that are not responsible for specific log implementations and are only responsible for finding the appropriate log system for binding at compile time. Specifically what interfaces, all defined in Slf4j-api.
- SLF4J-LOG4J12 is the adapter that links the middle of slf4j-api and log4j. It implements the Staticloggerbinder interface in the Slf4j-apiz, so that the Slf4j-log4j12 Getsingleton () method is bound at compile time
- The log4j is a specific log system. The output of the final log is reached by SLF4J-LOG4J12 initialization of the log4j.
- Lombok: A plugin that encapsulates the get and set of log, which can be used to output log information directly using log.
The specific use
@Slf4j
public class Validatoraction {
public void Printvalidatorresult (set<constraintviolation<validatorbean>> set1) {
for (constraintviolation<validatorbean> Constraintviolation:set1) {
Log.info ("Error:" +constraintviolation.getmessage ());
Log.info ("Field:" +constraintviolation.getpropertypath (). toString ());
}
}
}
Proper use of annotations @Slf4j the Java log system