Log4jdbc and Logback

Source: Internet
Author: User
Tags log4j

The use of LOG4JDBC in the project, can be very convenient to the SQL parameters also printed out, easy to debug the problem. Like the original Sql:select * from t_order where order_id =? After LOG4JDBC processing, it becomes a select * from t_order where order_id = 123. But after this processing, the default will print a lot of SQL-related information, such as connection, execution time, parameter binding, results and other information, will make the log printing rapid expansion, I here more frequent service calls, there are two scheduled tasks in the call service, log every day around 50G. The log4jdbc.properties was then configured, but with little effect. Later, the following configuration was added in Logback.xml:

    <Loggername= "Jdbc.sqlonly" Level= "ERROR">        <Appender-refref= "Rollingfile"/>    </Logger>    <Loggername= "Jdbc.audit" Level= "ERROR">        <Appender-refref= "Rollingfile"/>    </Logger>    <Loggername= "Jdbc.resultset" Level= "ERROR">        <Appender-refref= "Rollingfile"/>    </Logger>    <Loggername= "Jdbc.connection" Level= "ERROR">        <Appender-refref= "Rollingfile"/>    </Logger>

Set the print level of Jdbc.only, Jdbc.audit, Jdbc.resultset, jdbc.connection to error, reducing this part of the print, you can configure the level according to your own needs. Optimized to within 1G per day.

The configuration of the attached log4jdbc.properties is as follows:

log4j.logger.jdbc.sqlonly=debug,consolelog4j.appender.console= org.apache.log4j.consoleappenderlog4j.appender.console.layout= Org.apache.log4j.patternlayoutlog4j.appender.console.layout.conversionpattern=%d{yyyy-mm-dd HH:mm:ss. SSS}%m%n%nlog4j.logger.jdbc.sqltiming=debug,consolelog4j.logger.jdbc.connection=debug,console

Attempted to modify debug in the above file to be error, OFF is not valid. The conjecture is that because Logback takes over the output configuration of log, it must be configured in Logback. What is the reason behind the time to study again.

Log4jdbc and Logback

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.