2017-07-07 95 views
0

我有maven應用程序,其中包含log4j.properties,並設置爲將日誌寫入指定文件而不是控制檯。當我在其中一臺websphere服務器上運行EAR時,它會按預期創建文件並將日誌寫入其中。但是,當我在其他webspehere服務器上運行相同的EAR時,它將寫入控制檯而不是將日誌寫入指定的文件。我檢查了權限,一切似乎都沒有問題。請幫助我確定問題所在。提前致謝。Log4j不將日誌寫入一個Websphere服務器上的文件並寫入其他文件

# CONSOLE APPENDER (stdout) 
log4j.appender.stdout=org.apache.log4j.ConsoleAppender 
log4j.appender.stdout.Threshold=DEBUG 
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 
log4j.appender.stdout.layout.ConversionPattern=[%d] [%t] %-5p %20c - %m%n 

# ROLLING FILE APPENDER (on the file system) for memberpolicyattributesservice code 
log4j.appender.xxxxService=org.apache.log4j.RollingFileAppender 
log4j.appender.xxxxService.Threshold=DEBUG 
log4j.appender.xxxxService.File=/var/logs/xxxServer1/xxxServiceLog.log 
log4j.appender.xxxxService.layout=org.apache.log4j.PatternLayout 
log4j.appender.xxxxService.layout.ConversionPattern=%d{[email protected]:mm:ss} %-5p (%13F:%L) %3x - %m%n 
log4j.appender.xxxxService.MaxFileSize=10000KB 
log4j.appender.xxxxService.MaxBackupIndex=30 
log4j.appender.xxxxService.layout=org.apache.log4j.PatternLayout 
log4j.appender.xxxxService.layout.ConversionPattern=[%d] [%t] %-5p %20c - %m%n 



# ROLLING FILE APPENDER (on the file system) for hiberate, open source code log files 
log4j.appender.open_source_code=org.apache.log4j.RollingFileAppender 
log4j.appender.open_source_code.layout=org.apache.log4j.PatternLayout 
log4j.appender.open_source_code.Threshold=DEBUG 
#message format:YYYY-MM-DD HH:mm:ss,ms [ThreadId] <PRIORITY> classname.message 
log4j.appender.open_source_code.layout.ConversionPattern=%d [%t]<%-5p> %c.%m \r\n 
#file that will be logged to 
log4j.appender.open_source_code.File=/var/logs/xxxServer1/open_source_code.log 
log4j.appender.open_source_code.Append=true 
log4j.appender.open_source_code.MaxFileSize=1024KB 
log4j.appender.open_source_code.MaxBackupIndex=5 


#turn on log4j verbose mode 
log4j.debug = true 

# Set root logger level to INFO and its appender to DSInstrumentor,stdout. 
log4j.rootLogger=DEBUG,stdout,xxxxService 


# YOUR CATEGORIES (to customize logging per class/pkg/project/etc) 
log4j.category.fatal=FATAL,xxxxService 
log4j.category.error=ERROR,xxxxService 


#This will also enable the logging for all the children (packages and classes) of this package 

log4j.logger.com.xxxxx=ALL,xxxxService 

# Print only messages of level INFO in the open source code 
log4j.logger.org=INFO,open_source_code 

回答

0

你已經在你的根記錄(DEBUG,標準輸出,xxxxService),但xxxxService記錄器定義了多個記錄器看起來像他們必然要在文件系統上的系統之一:

log4j.appender .open_source_code.File =/var/logs/xxxServer1 /open_source_code.log

確保路徑對於WAS羣集中的每個服務器都有效。

請注意,您應該避免在遠程服務器上使用debug和stdout。這適用於工作站本地開發,但不適用於遠程機器。相反,請在各個部署層上提供不同的log4j屬性。這使您可以自定義日誌位置或appender(例如桌面上的c:\ temp或CONSOLE,但是所有遠程計算機上的/ var/logs ...)以及日誌級別(桌面的DEBUG,可能是QA的INFO或分段,WARN或ERROR進行生產)。

+0

感謝您的回覆。我甚至嘗試刪除根記錄器中的多個記錄器,發現它在服務器上無法工作。感謝關於日誌級別的建議,但我試圖在該服務器上首次部署應用程序,因此日誌級別爲「調試」而不是「信息」。 –

+0

這兩個服務器上的路徑是相同的,但日誌記錄仍在寫入其中一臺服務器上的控制檯,而它在其他服務器上正常工作。我仍然不明白是否需要更改任何服務器級別的配置。如果您知道任何問題,請告訴我。 –