簡體   English   中英

如何使用 log4j 和 log4j2 屬性文件登錄到同一文件

[英]How to use log4j and log4j2 properies file to log into same file

我想根據大小時間滾動和壓縮日志文件。 我發現使用 log4j2 可以很容易地執行此操作。 問題是許多內部 jars 仍然使用 log4j 進行日志記錄,我想記錄下來。

我在這里想到的可能的解決方案是通過使用log4j1.compatibility=true通過保持 log4j.properties 和 log4j2.properties

我想不通的是如何在 log4j.properties 和 log4j2 屬性中使用 RollingFileAppender?

請建議我如何使用屬性文件(log4j 和 log4j2)在達到特定大小或時間時通過自動壓縮記錄到同一個文件。

Note: I tried using uk.org.simonsite.log4j.appender.TimeAndSizeRollingAppender but getting error NoClassDefError: org.apache.log4j.xml.unrecognizedelementhandler due to class is removed in log4j versions greater than v1.2.17.

大多數庫只使用 Log4j 1.x 來記錄消息,它們不以編程方式配置日志系統。 因此,您可以簡單地將log4j替換為log4j-1.2-api

Log4j 1.x 橋 ( log4j-1.2-api ) 與 Log4j 2.x Core 共享其配置,因此您可以使用本機 Log4j 2.x 配置文件來配置RollingFileAppender 不需要log4j.properties文件或log4j1.compatibility屬性。

PS:在 Log4j 2.x(參見文檔)支持的 4 種配置文件格式中,屬性格式可能更為復雜。 我個人會選擇其余 3 個之一(XML、JSON 或 YAML)。 XML 格式不需要額外的依賴。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM