SLF4J + logback output log: MyBatis SQL statement

Source: Internet
Author: User

1 Introducing the JAR package: Maven resposity select Logback Classic Module

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>

2 Adding a logback.xml configuration file
<?xml version= "1.0" encoding= "UTF-8"?><configuration> <appender name= "Console" class= " Ch.qos.logback.core.ConsoleAppender "> <encoder> <pattern>%d{hh:mm:ss. SSS} [%thread]%-5level%logger{36}-%msg%n</pattern> </encoder> </appender> <appender Name= "Rollingfile" class= "Ch.qos.logback.core.rolling.RollingFileAppender" > <file>d:/logs/ carmall-manager.log</file> <rollingpolicy class= "Ch.qos.logback.core.rolling.TimeBasedRollingPolicy" > <fileNamePattern>d:/logs/carmall-manager.%d{yyyy-MM-dd}.log</fileNamePattern> </roll Ingpolicy> <encoder> <pattern>%d{hh:mm:ss. SSS} [%thread]%-5level%logger{36}-%msg%n</pattern> </encoder> </appender><!--package path to mapper files--<logger name= "Mapper" level= "Debug"/> <!--log4jdbc--<logger name= "jdbc.sqltiming" level= "Debug"/&    Gt <logger name= "Com.ibatis" level= "Debug"/> <logger name= "Com.ibatis.common.jdbc.SimpleDataSource" level= " Debug "/> <logger name=" Com.ibatis.common.jdbc.ScriptRunner "level=" Debug "/> <logger name=" com.ibatis.s Qlmap.engine.impl.SqlMapClientDelegate "level=" Debug "/> <logger name=" java.sql.Connection "Level=" Deb UG "/> <logger name=" java.sql.Statement "level=" Debug "/> <logger name=" Java.sql.PreparedStatement "leve l= "Debug"/> <logger name= "Java.sql.ResultSet" level= "Debug"/> <root level= "info" > <append Er-ref ref= "Console"/> <appender-ref ref= "Cn.iautos.manager"/> <appender-ref ref= "Com.ibatis" /> <appender-ref ref= "Rollingfile"/> </root></configuration>

Last output log

22:25:42,179 |-info in ch.qos.logback.classic.joran.action.loggeraction-setting level of logger [ Java.sql.PreparedStatement] to debug22:25:42,179 |-info in ch.qos.logback.classic.joran.action.loggeraction-setting level of logger [Java.sql.ResultSet] to debug22:25:42,179 |-info in Ch.qos.logback.classic.joran.action.rootloggeraction-setting level of the ROOT logger to info22:25:42,179 |-INFO in Ch.qos. logback.core.joran.action.appenderrefaction-attaching Appender named [console] to logger[root]22:25:42,180 |-ERROR in Ch.qos.logback.core.joran.action.appenderrefaction-could not find an appender named [Cn.iautos.manager]. Did you define it below instead of above in the configuration file?22:25:42,180 |-error in Ch.qos.logback.core.joran.actio N.appenderrefaction-see Http://logback.qos.ch/codes.html#appender_order for more details.22:25:42,180 |-error in Ch.qos.logback.core.joran.action.appenderrefaction-could not find an appender named [Com.ibatis]. Did you define it below InsteaD of above in the configuration file?22:25:42,180 |-error in Ch.qos.logback.core.joran.action.appenderrefaction-see http ://logback.qos.ch/codes.html#appender_order for more details.22:25:42,180 |-info in Ch.qos.logback.core.joran.action.appenderrefaction-attaching Appender named [Rollingfile] to Logger[root] 22:25:42,180 |-info in Ch.qos.logback.classic.joran.action.configurationaction-end of configuration.22:25:42,181 | | INFO in [email protected]-Registering current configuration as safe fallback point22:25:42.649 [main] DEBUG mapper. Usermapperi.getuser-==> Preparing:select * from users where id=? 22:25:42.704 [main] DEBUG mapper. Usermapperi.getuser-==> parameters:1 (Integer) 22:25:42.742 [main] DEBUG mapper. Usermapperi.getuser-<== total:1user{id= ' 1 ', name= ' test ', action= ' test '}

  

Recently added log in project

If this is the Spring boot project:
Just add the application.properties inside.

Logging.level.com. Your package name is =true. Just OK.


SLF4J + logback output log: MyBatis SQL statement

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.