Logback AyncAppender not printing File and Line number

痞子三分冷 提交于 2019-11-30 05:18:51

You need to set AsyncAppender's includeCallerData property to true. Here is the modified config file:

<configuration>
    <appender name="FILE" class="ch.qos.logback.core.FileAppender">
      <file>myapp.log</file>
      <encoder><pattern>%logger{35} - [%F:%L] - %msg%n</pattern></encoder>
    </appender>

    <appender name="ASYNC" class="ch.qos.logback.classic.AsyncAppender">
      <appender-ref ref="FILE" />
      <!-- add the following line -->
      <includeCallerData>true</includeCallerData>
    </appender>

    <root level="DEBUG"><appender-ref ref="ASYNC" /></root>
 </configuration>

I post same answer in groovy format for someone who want groovy style like me.

appender('FILE', ch.qos.logback.core.FileAppender) {
    file = 'myapp.log'
    encoder(PatternLayoutEncoder) {
        pattern = '%logger{35} - [%F:%L] - %msg%n'
    }
}
appender('ASYNC', ch.qos.logback.classic.AsyncAppender) {
    appenderRef('FILE')
    //add the following line
    includeCallerData = true
}

root(DEBUG, ['ASYNC'])
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!