文章分類

C# (27) ASP.NET (13) SQL (7) ORACLE (5) JAVA (2) SQLSERVER2008 (2) 大家都在問的事 (2) ACCESS (1) ANDRIOD (1) JQUERY (1) python (1) 雜談 (1)

關於我自己

我的相片
程式初心者 JAVA, ASP.NET, C# ,SQL

2017年4月10日 星期一

【JAVA】log4j設定- 產出不同等級的集合LOG

LOG4J的LOG的等級(LEVEL)包含五種這 5 種等級的高低順序為 FATAL > ERROR > WARN > INFO > DEBUG
以下的PROPITES範例示範單獨LEVEL還能有不同LEVEL的集合LOG

log4j.rootLogger=debug,stdout,ROLLING_FILE,Err,MixLog
log4j.logger.MixLog =ROLLING_FILE,Err

log4j.logger.MainClass=debug,ROLLING_FILE,Err,stdout
log4j.logger.SubClassr=debug,ROLLING_FILE,Err,stdout


#console顯示
log4j.appender.stdout = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target = System.out
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern =  %d{ABSOLUTE} %5p %c{1}:%L - %m%n

#1.只SHOW ERROR========================== 
log4j.appender.Err=org.apache.log4j.RollingFileAppender 
log4j.appender.Err.Threshold=ERROR
log4j.appender.Err.File=D:/Error/error.log  
log4j.appender.Err.Append=true
log4j.appender.Err.MaxFileSize=100MB
log4j.appender.Err.MaxBackupIndex=30 
log4j.appender.Err.layout=org.apache.log4j.PatternLayout
log4j.appender.Err.layout.ConversionPattern==%d [%t] %-5p %c - %m%n 

#2.只SHOW INFO===================== 
log4j.appender.ROLLING_FILE=org.apache.log4j.RollingFileAppender 
log4j.appender.ROLLING_FILE.Threshold=INFO
log4j.appender.ROLLING_FILE.File=D:/Info/rolling.log
log4j.appender.ROLLING_FILE.Append=true 
log4j.appender.ROLLING_FILE.MaxFileSize=100MB 
log4j.appender.ROLLING_FILE.MaxBackupIndex=30 
log4j.appender.ROLLING_FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.ROLLING_FILE.layout.ConversionPattern==%d [%t] %-5p %c - %m%n 

#3.SHOW INFO+ERROR=====================
log4j.appender.MixLog=org.apache.log4j.RollingFileAppender
log4j.appender.MixLog.Threshold=INFO
log4j.appender.MixLog.File=D:/MIX/rolling.log
log4j.appender.MixLog.Append=true 
log4j.appender.MixLog.MaxFileSize=100MB 
log4j.appender.MixLog.MaxBackupIndex=30 
log4j.appender.MixLog.layout=org.apache.log4j.PatternLayout
log4j.appender.MixLog.layout.ConversionPattern==%d [%t] %-5p %c - %m%n