如何在 mule 應用程序中實現 log4j2 (2.14.0) 'JSON 模板佈局'? (How can I implement log4j2 (2.14.0) 'JSON Template Layout' in a mule application?)


問題描述

如何在 mule 應用程序中實現 log4j2 (2.14.0) 'JSON 模板佈局'? (How can I implement log4j2 (2.14.0) 'JSON Template Layout' in a mule application?)

Log4j2 實現了“JSON 模板佈局”。我已經能夠在標準的 maven java 應用程序中實現它,但是我無法在 Mule 4.3 應用程序中實現它。我已將 log4j2 (2.14.0) 依賴項添加到我的 POM:

    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j‑api</artifactId>
      <version>2.14.0</version>
    </dependency>
    <dependency>
       <groupId>org.apache.logging.log4j</groupId>
       <artifactId>log4j‑core</artifactId>
       <version>2.14.0</version>
      </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j‑layout‑template‑json</artifactId>
        <version>2.14.0</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson‑core</artifactId>
        <version>2.12.1</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson‑databind</artifactId>
        <version>2.12.1</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson‑annotations</artifactId>
        <version>2.12.1</version>
    </dependency>

Log4j2 Appender Config

<Appenders>
    <Console name="CONSOLE" target="SYSTEM_OUT">
       <JsonTemplateLayout />
    </Console>
</Appenders>

我看到它們已加載到日誌中,但出現錯誤:

2021‑02‑06 07:17:39,175 WrapperListener_start_runner DEBUG 構建插件 [name=layout, class=org.apache.logging.log4j.layout.template.json.JsonTemplateLayout]。2021‑02‑06 07:17:39,179 WrapperListener_start_runner 錯誤無法為元素 JsonTemplateLayout 創建類型為 org.apache.logging.log4j.layout.template.json.JsonTemplateLayout 的插件:java.util.UnknownFormatConversionException:


參考解法

方法 1:

Mule 4 provides log4j2 to applications. It is one of few libraries that actually may override application's libraries in Mule 4. You should use what is provided. Do not try to change any provided libraries with different versions, that is not supported.

(by Ozsafferaled)

參考文件

  1. How can I implement log4j2 (2.14.0) 'JSON Template Layout' in a mule application? (CC BY‑SA 2.5/3.0/4.0)

#log4j2 #mule #mulesoft






相關問題

Làm cách nào để thêm phần phụ Log4J2 vào thời gian chạy theo chương trình? (How to add Log4J2 appenders at runtime programmatically?)

使用 Spring 和 Log4j2 的 Classloader-Leak (Classloader-Leak with Spring and Log4j2)

log4j2 RolllingFileAppender filePattern 創建日期錯誤 (log4j2 RolllingFileAppender filePattern create a wrong date)

將時間戳添加到日誌文件名時出錯 (log4j2) (Error adding timestamp to log file name (log4j2))

log4j2 - 以編程方式更改 RollingFileAppender 的最大文件大小 (log4j2 - programmatically change max file size of RollingFileAppender)

log4j 沒有登錄到文件或控制台 (log4j is not logging into file or console)

Log4j2 未在 Linux 中使用 Spring Boot 創建日誌文件 (Log4j2 not creating log file with Spring Boot in Linux)

application.properties 中的外部 log4j2.xml 文件路徑 (External log4j2.xml file path in application.properties)

使用 Spring 的依賴於配置文件的 log4j2 配置 (Profile-dependent log4j2 configuration with Spring)

從 log4j2.xml 訪問環境變量 (Accessing environment variable from log4j2.xml)

Spring Boot 應用程序中的內部 tomcat 停止響應調用 (internal tomcat inside spring boot application stops responding to calls)

如何在 mule 應用程序中實現 log4j2 (2.14.0) 'JSON 模板佈局'? (How can I implement log4j2 (2.14.0) 'JSON Template Layout' in a mule application?)







留言討論