Logback AyncAppender not printing File and Line number

前端 未结 2 703
自闭症患者
自闭症患者 2020-12-29 12:52

I have the following configuration file that is very similar to the standard example in the Logback manual. The only difference is the addition of [%F:%L]. while everything

相关标签:
2条回答
  • 2020-12-29 13:08

    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'])
    
    0 讨论(0)
  • 2020-12-29 13:30

    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>
    
    0 讨论(0)
提交回复
热议问题