Proper use of annotations @Slf4j the Java log system

Source: Internet
Author: User
Tags log4j

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.