MyBatis adding logs using log4j

Source: Internet
Author: User

Thx
http://ppyymm000.blog.163.com/blog/static/2834658420121141142231/http://blog.163.com/[email protected] /blog/static/170162360201392105823927/

---------------------------------------dividing line is my reserved---------------------------------------

Many times you need to look at the SQL statements executed by MyBatis, as well as the execution. We need to add a configuration in the log4j configuration file.

Log4j.rootlogger=debug, sqllog4j.appender.sql= Org.apache.log4j.dailyrollingfileappenderlog4j.appender.sql.datepattern= '. ' yyyymmddlog4j.appender.sql.file=e:\log\sql.loglog4j.appender.sql.layout= Org.apache.log4j.patternlayoutlog4j.appender.sql.layout.conversionpattern=%d{yyyy-mm-dd HH\:mm\:ss} | %m%nlog4j.logger.org.apache.ibatis=debuglog4j.logger.org.apache.common.jdbc.simpledatasource= Debuglog4j.logger.org.apache.common.jdbc.scriptrunner= debuglog4j.logger.org.apache.sqlmap.engine.impl.sqlmapclientdelegate=debuglog4j.logger.java.sql.connection= Debuglog4j.logger.java.sql.statement=debuglog4j.logger.java.sql.preparedstatement= Debuglog4j.logger.java.sql.resultset=debug

Do not know how the MyBatis internal about this log is configured. After testing, MyBatis's appender used the same one as the root level Rootlogger .

It is said that # MyBatis logging configuration ... This allows the output of the log for the namespace of the package, interface, method, or mapper

Using the above configuration has been able to meet my needs

 --Geneva-Geneva  -: Geneva: - |Acquired Connection[jdbc:mysql://localhost:3306/db?useunicode=true&characterencoding=utf-8, [email protected], MySQL Connector Java]  forJdbcTransaction --Geneva-Geneva  -: Geneva: - |Setting JDBC Connection[jdbc:mysql://localhost:3306/db?useunicode=true&characterencoding=utf-8, [email protected], MySQL Connector Java] Read- only --Geneva-Geneva  -: Geneva: - |Switching JDBC Connection[jdbc:mysql://localhost:3306/db?useunicode=true&characterencoding=utf-8, [email protected], MySQL Connector Java]  toManualCommit --Geneva-Geneva  -: Geneva: - |Creating a new sqlsession --Geneva-Geneva  -: Geneva: - |RegisteringTransactionSynchronization forSqlsession[[email protected]] --Geneva-Geneva  -: Geneva: the |JDBC Connection[jdbc:mysql://localhost:3306/db?useunicode=true&characterencoding=utf-8, [email protected], MySQL Connector Java]would be managed bySpring --Geneva-Geneva  -: Geneva: the | ==>Preparing:SelectId from User WHERELogin_name=? andPassword= ?  --Geneva-Geneva  -: Geneva: the | ==>Parameters:hehe (String), f379eaf3c831b04de153469d1bec345e (String) --Geneva-Geneva  -: Geneva: the | <==Total:1 --Geneva-Geneva  -: Geneva: the |Releasing Transactional sqlsession[[email protected]] --Geneva-Geneva  -: Geneva: the | TransactionSynchronization committing Sqlsession[[email protected]] --Geneva-Geneva  -: Geneva: the | TransactionSynchronization deregistering sqlsession[[email protected]] --Geneva-Geneva  -: Geneva: the | TransactionSynchronization closing Sqlsession[[email protected]] --Geneva-Geneva  -: Geneva: the |InitiatingTransaction Commit --Geneva-Geneva  -: Geneva: the |Committing JDBCTransaction  onConnection[jdbc:mysql://localhost:3306/db?useunicode=true&characterencoding=utf-8, [email protected], MySQL Connector Java] --Geneva-Geneva  -: Geneva: the |ResettingRead- onlyFlag ofJDBC Connection[jdbc:mysql://localhost:3306/db?useunicode=true&characterencoding=utf-8, [email protected], MySQL Connector Java] --Geneva-Geneva  -: Geneva: the |Releasing JDBC Connection[jdbc:mysql://localhost:3306/db?useunicode=true&characterencoding=utf-8, [email protected], MySQL Connector Java]AfterTransaction --Geneva-Geneva  -: Geneva: the |Returning JDBC Connection toDataSource

MyBatis adding logs using log4j

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.