Hello World

Log4j2:异步日志中打印方法名和行号信息

1. 解决方案

  1. 异步logger,还需要在pom.xml中添加disruptor的依赖;
  2.  includeLocation结合异步logger使用,当其设置为true时,才会显示具体的行号,以及日志所在的类名;
  3. 如果设置为false,哪怕<Pattern>设置了输出行号也不会显示出来;

2. pom配置

      <dependency>
            <groupId>com.lmax</groupId>
            <artifactId>disruptor</artifactId>
            <version>3.3.6</version>
        </dependency>

3. 属性配置

  设置 AsyncRoot 的 includeLocation 属性为 true;

  xml 格式示例:

<AsyncRoot level="info" includeLocation="true">
    <AppenderRef ref="File"/>
</AsyncRoot>

  yaml 格式示例:

  Loggers:
      AsyncRoot:
        level: info
        includeLocation: true
        AppenderRef:
          - ref: console
          - ref: running_log
posted @ 2020-01-07 17:14  小小忧愁米粒大  阅读(4573)  评论(0编辑  收藏  举报
瞅啥瞅,好好看书