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

Druid version:

 <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>druid</artifactId>
                <version>1.1.6</version>
            </dependency>

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:

Content:

<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.

logback.xml 

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <!--
    %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(TestLog4.java:10)
    -->
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d |-%p %class:%line - %m%n</pattern><!-- Format output here -->
            <charset>UTF-8</charset> <!-- Set character set here -->
        </encoder>
    </appender>
    <appender name="fileLogger"
              class="ch.qos.logback.core.rolling.RollingFileAppender">
        <File>/data/app/logs/cloudx/o2o-service.log</File>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>/data/app/logs/cloudx/o2o-service-%d-%i.log</fileNamePattern>
            <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <!-- Maximum storage of log files 64 MB -->
                <maxFileSize>64 MB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
        </rollingPolicy>
        <encoder>
            <pattern>%d |-%p %class:%line - %m%n</pattern>
            <charset>UTF-8</charset> <!-- Set character set here -->
        </encoder>
    </appender>

  

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


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

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: https://blog.csdn.net/qq_42145871/article/details/90704632

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 https://www.bookstack.cn/read/Druid/2fa0c5cdf8a9e77e.md
 
 GitHub :  https://github.com/alibaba/druid/wiki

Tags: Programming Druid log4j SQL xml

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