#http://wolfsquare.javaeye.com/blog/38686
#http://www.roboticfan.com/blog/user_2005/104/archives/2009/200974225459.shtml
#定義一個名為 stdout 的appender和layout
#定義stdout的輸出類
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
#定義stdout的輸出裝飾器
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
#裝飾器的配置
log4j.appender.stdout.layout.ConversionPattern=%d{MM-dd HH/:mm/:ss.SSS} %-5p [%F/:%L]%x %m%n
#定義一個名為 fileout 的appender和layout
log4j.appender.fileout=org.apache.log4j.RollingFileAppender
log4j.appender.fileout.File=D:/workspace/log4jtest/log/application.log
log4j.appender.fileout.MaxFileSize=10000KB
log4j.appender.fileout.MaxBackupIndex=10
log4j.appender.fileout.layout=org.apache.log4j.PatternLayout
log4j.appender.fileout.layout.ConversionPattern=%d{MM-dd HH:mm:ss.SSS}[%24F:%-3L:%-5p]%x %m%n
#定義了名字分別為rootCategory,logger.com.wolfsquare.log2的兩個logger
log4j.rootCategory=INFO, stdout, fileout
#rootCategory logger是缺省的logger,紀錄所有的包的信息輸出。
#rootCategory 把所有類的INFO級別以上的信息輸出到stdout和fileout兩個appender中
log4j.logger.com.wolfsquare.log2=DEBUG,stdout
#logger是只輸出指定包com.wolfsquare.log2下的日志信息.
#把com.wolfsquare.log2包中的所有類(包括子包)DEBUG級別(含)以上的信息輸出到stdout 中
log4j.properties(例子1)
log4j.rootLogger=INFO, logfile, MAIL
log4j.appender.logfile=org.apache.log4j.DailyRollingFileAppender
log4j.appender.logfile.File=/logs/smsSendOut.log
#log4j.appender.logfile.File=d:/MGM.log
# Pattern to output: date priority [category] - message
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern=%d{yyyy/MM/dd HH:mm:ss} %C %p - %m%n
#SMTPAppender
#log4j.rootLogger = INFO,MAIL
log4j.appender.MAIL = org.apache.log4j.net.SMTPAppender
log4j.appender.MAIL.Threshold=ERROR
log4j.appender.MAIL.BufferSize = 1
log4j.appender.MAIL.SMTPHost = mail.cti.hkbn.com.hk
log4j.appender.MAIL.From = 廣州IT@www.domain.net
log4j.appender.MAIL.Subject = MGM SMS alarm email(UAT)
log4j.appender.MAIL.To = emailName@emailDoamin
#log4j.appender.MAIL.SMTPUsername=jzp24
#log4j.appender.MAIL.SMTPPassword=jzpsj2008
log4j.appender.MAIL.layout = org.apache.log4j.PatternLayout
log4j.appender.MAIL.layout.ConversionPattern=%d{yyyy/MM/dd HH:mm:ss} %C %p - %m%n
log4j.properties(例子2)
log4j.rootLogger=INFO, logfile
log4j.appender.logfile=org.apache.log4j.DailyRollingFileAppender
log4j.appender.logfile.File=/logs/bn_premium.log
#log4j.appender.logfile.File=d:/bn_premium.log
# Pattern to output: date priority [category] - message
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern=%d{yyyy/MM/dd HH:mm:ss} %C %p - %m%n
#add credit card logs(0909-2890)
log4j.additivity.creditCardFile=false
log4j.logger.creditCardFile=INFO, creditCardFile
log4j.appender.creditCardFile=org.apache.log4j.DailyRollingFileAppender
log4j.appender.creditCardFile.File=/logs/creditCardLogger.log
#log4j.appender.logfile.File=d:/iperftestlogin.log
# Pattern to output: date priority [category] - message
log4j.appender.creditCardFile.layout=org.apache.log4j.PatternLayout
log4j.appender.creditCardFile.layout.ConversionPattern=%d{yyyy/MM/dd HH:mm:ss} %C %p - %m%n
java:
private static Logger log = Logger.getLogger("Console");
private static Logger emailLogger = Logger.getLogger("MAIL");
PropertyConfigurator.configure(log4j.properties文件全路徑);
tomcat:
private static Log creditCardLogger = LogFactory.getLog("creditCardFile"); //結合common-logging.jar