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