简体   繁体   中英

some queries regarding log4j settings?

I have below settings for log4j.properties. But all log text whether info,debug,exception,fatal goes to MyDebugFile . No file prefixed with exception is created.
My question are:

  1. Can I mention same file for log4j.appender.EXCEPTION_LOG_FILE and log4j.appender.DEBUG_LOG_FILE
  2. What does property log4j.appender.EXCEPTION_LOG_FILE.Threshold specify?
  3. Why is the file prefixed with exception is not created?

Set up the format for messages logged to the Exception log file.

 log4j.appender.EXCEPTION_LOG_FILE=biz.minaret.log4j.DatedFileAppender
 log4j.appender.EXCEPTION_LOG_FILE.Threshold=INFO
 log4j.appender.EXCEPTION_LOG_FILE.Directory=C:/log/
 log4j.appender.EXCEPTION_LOG_FILE.Prefix=exception.
 log4j.appender.EXCEPTION_LOG_FILE.Suffix=.log
 log4j.appender.EXCEPTION_LOG_FILE.layout=org.apache.log4j.PatternLayout
 log4j.appender.EXCEPTION_LOG_FILE.layout.ConversionPattern=%d [%t] %-5p %c{3} - %m%n
 log4j.appender.EXCEPTION_LOG_FILE.MaxFileSize=100KB
 log4j.appender.EXCEPTION_LOG_FILE.MaxBackupIndex=4

Set up the format for messages logged to the debug log file.

 log4j.appender.DEBUG_LOG_FILE=biz.minaret.log4j.DatedFileAppender
 log4j.appender.DEBUG_LOG_FILE.Directory=C:/log/
 log4j.appender.DEBUG_LOG_FILE.Prefix=MyDebugFile.
 log4j.appender.DEBUG_LOG_FILE.Suffix=.log
 log4j.appender.DEBUG_LOG_FILE.layout=org.apache.log4j.PatternLayout
 log4j.appender.DEBUG_LOG_FILE.layout.ConversionPattern=%d [%t] %-5p %c{3} - %m%n
 log4j.appender.DEBUG_LOG_FILE.MaxFileSize=100KB
 log4j.appender.DEBUG_LOG_FILE.MaxBackupIndex=4
  1. Can I mention same file for log4j.appender.EXCEPTION_LOG_FILE and log4j.appender.DEBUG_LOG_FILE

--> I don't think log4j really supports two appenders writing to the same file because of synchronization issues.

2 . What does property log4j.appender.EXCEPTION_LOG_FILE.Threshold specify?

--> Read an article here.

3 . Why is the file prefixed with exception is not created?

--> For this I don't have any idea.

This should help you

log4j.rootLogger=EXCEPTION_LOG_FILE, DEBUG_LOG_FILE

setup A1

log4j.appender.EXCEPTION_LOG_FILE=org.apache.log4j.RollingFileAppender log4j.appender.EXCEPTION_LOG_FILE.Threshold=INFO log4j.appender.EXCEPTION_LOG_FILE.File=exception.log ...

setup A2

log4j.appender.DEBUG_LOG_FILE=org.apache.log4j.RollingFileAppender log4j.appender.DEBUG_LOG_FILE.Threshold=DEBUG log4j.appender.DEBUG_LOG_FILE.File=MyDebugFile.log

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM