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


問題描述

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

我在我的項目中使用 log4j2,我已經外部化了 application.properties 和 log4j2.xml,我想在 application.properties 中提供 log4j2.xml 文件路徑

log4j2.xml 和 application.properties與 jar 位於同一目錄中的 config 文件夾中。

這是我的依賴項

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring‑boot‑starter‑log4j2</artifactId>
</dependency>

目錄結構:/tmp/myproj/conf/application.properties

/tmp/myproj/conf/log4j2.xml

/tmp/myproj/my.jar

任何幫助將不勝感激。


參考解法

方法 1:

Spring Boot expects the log4j2‑spring.xml configuration file to be on the classpath. However, you can store it in a different location and point to it using the logging.config property in application.properties.

Try providing below configuration to you application.properties. Here log4j2‑spring.xml is on project classpath. If not then try giving your full path as (suppose) "C:/tmp/myproj/conf/log4j2.xml".

**logging.config=classpath:log4j2‑spring.xml**
logging.level.org.springframework.web=INFO
logging.file=logs/spring‑boot‑logging.log

The configuaration in bold should work for you.

Then you need to configure your log4j2‑spring.xml as per your requirement. (simple and also for appenders, see here https://howtodoinjava.com/log4j2/log4j‑2‑xml‑configuration‑example/ ).

Note: I have used log4j2‑spring.xml in place of you log4j2.xml. you can replace at your will.

(by Taufik PirjadeJabongg)

參考文件

  1. External log4j2.xml file path in application.properties (CC BY‑SA 2.5/3.0/4.0)

#log4j2 #spring-boot #application.properties






相關問題

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?)







留言討論