如何配置logback.xml只输出'handler method','sql'和'error exception'?

时间:2017-02-24 15:38:13

标签: spring hibernate logback

我只想要(o.a.coyote.http11.Http11InputBuffer)和(org.hibernate.SQL)和(错误异常)

示例:

23:37:00.420 [http-nio-8017-exec-5] DEBUG o.a.coyote.http11.Http11InputBuffer - Received [GET /favicon.ico HTTP/1.1
Host: localhost:8017
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36
Accept: image/webp,image/*,*/*;q=0.8
Referer: http://localhost:8017/admin/feedback/list?callback=jQuery31107034830591424046_1487949767952&page=0&page_size=10&sortName=createTime&sortOrder=desc&user_nickname=12&content=23&versionName=34&systemInfo=45&token=null&_=1487949767961
Accept-Encoding: gzip, deflate, sdch, br
Accept-Language: zh-CN,zh;q=0.8
Cookie: Idea-838fc851=51ce98fb-b8d2-48e3-88f9-23e8648e8b91

]

23:37:00.361 [http-nio-8017-exec-4] DEBUG org.hibernate.SQL - select * from feedback f where f.user_id in (select id from user where nickname like ?) and f.content like ? and f.version_name like ? and f.system_info like ? 
#pageable
 order by f.CREATE_TIME desc limit ?

1 个答案:

答案 0 :(得分:0)

似乎我设法解决了。

<?xml version="1.0" encoding="UTF-8"?>
<configuration>

    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <Pattern>%d{yyyy-MM-dd_HH:mm:ss.SSS} %-5level %logger{36} - %msg%n</Pattern>
        </encoder>
    </appender>

    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>logs/log.log</file>
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <Pattern>%d{yyyy-MM-dd_HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</Pattern>
        </encoder>

        <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
            <FileNamePattern>logs/log.%i.log.zip</FileNamePattern>
            <MinIndex>1</MinIndex>
            <MaxIndex>10</MaxIndex>
        </rollingPolicy>

        <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
            <MaxFileSize>30MB</MaxFileSize>
        </triggeringPolicy>

    </appender>

    <logger name="org.apache.coyote.http11.Http11InputBuffer" level="DEBUG"/>
    <logger name="org.hibernate" level="DEBUG"/>

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

</configuration>