Logback AyncAppender不打印文件和行号 [英] Logback AyncAppender not printing File and Line number

查看:2157
本文介绍了Logback AyncAppender不打印文件和行号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下配置文件与Logback手册中的标准示例非常相似。唯一的区别是添加[%F:%L]。一切正常,%F和%L不起作用。如果我删除异步appender并直接使用文件appender,一切都很好。

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 works, %F and %L do not work. If I remove the async appender and log directly using the file appender, everything works just great.

有人可以解释发生了什么吗?以及如何打印这两个参数的文件名和行号?

can somebody explain what is going on? And how to print the file name and line number as these two parameters are supposed to?

<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" />
    </appender>
   <root level="DEBUG"><appender-ref ref="ASYNC" /></root>
 </configuration>


推荐答案

您需要设置AsyncAppender的 includeCallerData 属性为true。以下是修改后的配置文件:

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>

这篇关于Logback AyncAppender不打印文件和行号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆