ali druid filters log4j is not configured properly, which leads to disorderly printing of bugs executing SQL logs

Druid version:


The project uses spring boot + jpa + druid, and LOG is logback. druid does not print SQL content before it is transformed into microservice

After being transformed into microservice, the following logs appeared soon:


<2013-07-10 13:29:29> <DEBUG> - {conn-10031} pool-connect
<2013-07-10 13:29:29> <DEBUG> - {conn-10031} pool-connect
<2013-07-10 13:29:29> <DEBUG> - {conn-10031} setAutoCommit false

<2013-07-10 13:29:29> <DEBUG> - {conn-10031, pstmt-20048} Types : []
<2013-07-10 13:29:29> <DEBUG> - {conn-10031, pstmt-20048} Types : []
<2013-07-10 13:29:29> <DEBUG> - {conn-10031, pstmt-20048, rs-50060} query executed. 94.01312 millis. select ... where 1=1
<2013-07-10 13:29:29> <DEBUG> - {conn-10031, pstmt-20048, rs-50060} query executed. 94.01312 millis. select ... where 1=1


<2013-07-10 13:29:29> <DEBUG>  - {conn-10031, pstmt-20048, rs-50061} open
9> {conn-10031} commited

It's very strange.


<?xml version="1.0" encoding="UTF-8"?>
    %m Messages specified in the output code
    %p Output priority, i.e DEBUG,INFO,WARN,ERROR,FATAL
    %r The output starts from the application to the output of the log Milliseconds spent on information
    %c Output the category to which it belongs, usually the full name of the class
    %t Output the name of the thread that generated the log event
    %n Output a carriage return line feed, Windows The platform is "\r\n",Unix The platform is "\n"
    %d The date or time of the output log time point. The default format is ISO8601,You can also specify the format after, for example:%d{yyy MMM dd HH:mm:ss,SSS},Similar output: October 18, 2002 22:10:28921
    %l The location of the output log event, including the category name, the thread that occurred, and the number of lines in the code. Give an example: Testlog4.main(
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
            <pattern>%d |-%p %class:%line - %m%n</pattern><!-- Format output here -->
            <charset>UTF-8</charset> <!-- Set character set here -->
    <appender name="fileLogger"
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <!-- Maximum storage of log files 64 MB -->
                <maxFileSize>64 MB</maxFileSize>
            <pattern>%d |-%p %class:%line - %m%n</pattern>
            <charset>UTF-8</charset> <!-- Set character set here -->


    <root level="INFO">
        <appender-ref ref="STDOUT"/>

    <logger name="com.newpearl" level="DEBUG">
        <appender-ref ref="fileLogger"/>

Log configuration print information is only print info level information, how to print druid's sql log to the console?


The filter configured for druid is:

filters: stat,wall,log4j

If log4j is configured, it will not work normally.


Final solution

Refer to logback to configure druid:

Change the filter to:

filters: stat,wall,slf4j

You can fix the above exceptions.

Because after being transformed into a microservice, some packages rely on the log4j package,

Then configure the log4j filter, Druid uses the default log4j configuration, and prints the contents to the console


Document reference of ali druid

Because druid is given to Apache, but the druid of Apache means that you can't understand it at all. It's totally different.

Reference document address is attached here

druid Of
 GitHub :

Tags: Programming Druid log4j SQL xml

Posted on Fri, 20 Mar 2020 07:54:14 -0700 by linuxdoniv