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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM