2017-01-09 224 views
-1

Log4j不會將日誌文件寫入文件,而是寫入控制檯。我搜索了很多資源(我認爲這個問題已經存在),但無法找到解決方案。log4j不將日誌寫入文件

的Log4j版本1.2.17

下面是我的log4j的配置:

log4j.rootLogger = INFO,標準輸出log4j.rootCategory = INFO,標準輸出,文件

log4j.appender .stdout = org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout = org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern =%d {ABSOLUTE}%5p%t %C {20}:%L - %米%N

log4j.category.org.springframework = ERROR log4j.category.org.springframework.beans.factory = ERROR log4j.category.com.mypackage = INFO log4j.logger.org.springframework = ERROR log4j.logger.org.hibernate = ERROR log4j.logger.org.hibernate.persister.entity = ERROR

log4j.appender.File = org.apache.log4j .rolling.RollingFileAppender log4j.appender.File.File =/TMP/mylog.log log4j.appender.File.ImmediateFlush =真 log4j.appender.File.threshold = INFO log4j.appender.File.Append =真 log4j.appender.File.MaxFileSize = 10MB log4j.appender.File.MaxBackupIndex = 20 log4j.appender.File.layout = org.apache.log4j.PatternLayout log4j.appender.File.layout.ConversionPattern =%d { ABSOLUTE}%5P%噸 %C {2}:%L - %米%N log4j.appender.File.rollingPolicy = org.apache.log4j.rolling.TimeBasedRollingPolicy log4j.appender.File.rollingPolicy.FileNamePattern = /tmp/mylog%d.log log4j.appender.File.layout.ConversionPattern =%d {ABSOLUTE}%5P%噸 %C {2}:%L - %米%N

我有確保我有權訪問ia的目錄試圖寫信給。 有人可以幫我嗎?

回答

0

請對你的配置文件進行下面提到的修改。

log4j.appender.file=org.apache.log4j.rolling.RollingFileAppender 
log4j.appender.file.File=/tmp/mylog.log 
log4j.appender.file.ImmediateFlush=true 
log4j.appender.file.threshold=INFO 
log4j.appender.file.Append=true 
log4j.appender.file.MaxFileSize=10MB 
log4j.appender.file.MaxBackupIndex=20 
log4j.appender.file.layout=org.apache.log4j.PatternLayout 
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %t %c{2}:%L - %m%n 
log4j.appender.file.rollingPolicy=org.apache.log4j.rolling.TimeBasedRollingPolicy 
log4j.appender.file.rollingPolicy.FileNamePattern=/tmp/mylog%d.log 
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %t %c{2}:%L - %m%n 

希望這工作正常。

+0

您覺得這有幫助嗎? –