MyBatis output log with log4j, output SQL to console

Source: Internet
Author: User
Tags log4j

Log4jar Package +log4j.properties Baidu Cloud Permanent Effective: https://pan.baidu.com/s/15WZ-lcBPgFa-a6lkTVVvYw

1 Import the jar package (directly copy the jar package into the Lib directory, then build path), and then create a new log4j.properties file: Baidu Cloud has log4j writing standard tutorial.

Log4j.rootlogger=INFO, stdout, Rlog4j.appender.stdout=Org.apache.log4j.ConsoleAppenderlog4j.appender.stdout.layout=org.apache.log4j.patternlayout# Pattern to output the caller' s file name and line number. #log4j. appender.stdout.layout.conversionpattern=%5p [%t] (%f:%l)-%m%n# Print The date in ISO8601Formatlog4j.appender.stdout.layout.ConversionPattern=%d [%t]%-5p%c-%m%NLOG4J.APPENDER.R=Org.apache.log4j.rollingfileappenderlog4j.appender.r.file=example.loglog4j.appender.r.maxfilesize=100kb# Keep One backup Filelog4j.appender.r.maxbackupindex=1Log4j.appender.r.layout=Org.apache.log4j.patternlayoutlog4j.appender.r.layout.conversionpattern=%p%t%c-%m%n# Print Only messages of level WARN or above in the PackageCOM.FOO.LOG4J.LOGGER.COM.IMOOC=info

2 Creating a tool class

 Public class Log {                publicstatic Logger Logger =  logger.getlogger (log.  Class. GetName ());    }

3 Direct call.

Like what:

catch (Exception e) {Log.logger.error (E.getmessage ()); E.printstacktrace ();}

  

Log.logger.info ("The parameter you passed in");

If you want to make SQL statements or some database information in the console: To configure in Mybatis.xml:

<settings><setting name= "Logimpl" value= "stdout_logging"/>     <settings>

MyBatis output The log with log4j, and output SQL to the console

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.