問題描述
如何在 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.
參考文件