0

以下是 log4j 属性文件内容。我正在尝试通过定义两个日志附加程序将 WARN 日志写入两个不同的不同日志文件,如下所示。

问题:日志写入两个文件(重复)。

log4j.rootLogger=WARN, A1, xmlout, GPSMSPLogger
#log4j.rootLogger=DEBUG, xmlout
log4j.logger.mailLogger=ALL, mail

log4j.category.com.moodys=INFO

# Setting additivity to false
# For not writing same logs into two files
# R3'13 
log4j.additivity.org.apache=false
log4j.additivity.A1=false;
log4j.additivity.GPSMSPLogger=false;
log4j.logger.GPSMSPLogger=DEBUG,GPSMSPLogger

# A1 is set to be a ConsoleAppender.
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.threshold=DEBUG
# A1 uses PatternLayout.
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c %x %m%n


# xmlout is set to be a DatedFileAppender
log4j.appender.xmlout=biz.minaret.log4j.DatedFileAppender
log4j.appender.xmlout.Threshold=DEBUG
#log4j.appender.xmlout.Directory=e\:\\logs\\surveillance.
#log4j.appender.xmlout.Prefix=surveillance
#log4j.appender.xmlout.Suffix=.log
log4j.appender.xmlout.Append=true
log4j.appender.xmlout.layout=org.apache.log4j.xml.XMLLayout


log4j.appender.mail=org.apache.log4j.net.SMTPAppender
#log4j.appender.mail.To=dmitry.nikelshpur@moodys.com
#log4j.appender.mail.To=valeriy.vinnychuk@moodys.com
log4j.appender.mail.To=Moody's-SFGSMART@moodys.com
log4j.appender.mail.From="SFG SMART Application Mailer [Dmitry Nikelshpur]"
# Q2'12
#log4j.appender.mail.SMTPHost=mdynycmsxswp.moodys.com
log4j.appender.mail.SMTPHost=${SMTP.MAIL.SERVER}
# Q2'12 
log4j.appender.mail.Threshold=ERROR
log4j.appender.mail.BufferSize=1
log4j.appender.mail.Subject=Test Surveillance logger email handler *** PLEASE DISREGARD *** 
log4j.appender.mail.layout=com.moodys.sfg.smart.util.SMARTMailerHTMLLayout
log4j.additivity.mailLogger=true
log4j.appender.mail.layout.LocationInfo=true


# R3'13
# Setup GPSMSPLogger
log4j.appender.GPSMSPLogger=biz.minaret.log4j.DatedFileAppender
log4j.appender.GPSMSPLogger.layout=org.apache.log4j.PatternLayout
log4j.appender.GPSMSPLogger.layout.ConversionPattern=%d [%t] %-5p %c %x %m%n
log4j.appender.GPSMSPLogger.Directory=${msp.log.directory}
log4j.appender.GPSMSPLogger.Prefix=gps_msp.
log4j.appender.GPSMSPLogger.Suffix=.log
log4j.appender.GPSMSPLogger.Threshold=DEBUG

以下是用于记录的代码:

public class GPSMSPLogger {

public static Logger getLogger(){

return Logger.getLogger("GPSMSPLogger");

}

public static void main(String arg[]){

getLogger().info("Log example INFO.......... ");

}

}
4

1 回答 1

0

您需要删除这些行上的尾随分号:

log4j.additivity.A1=false;
log4j.additivity.GPSMSPLogger=false;

可加性值应该是truefalse,而不是false;

于 2013-10-31T15:00:06.467 回答