slf4j 和 log4j合用的(Maven)配置

步驟:apache

1. 在Maven的porn.xml 文件中添加dependency以下api

1 <dependency>  
2     <groupId>org.slf4j</groupId>  
3     <artifactId>slf4j-log4j12</artifactId>  
4     <version>1.7.2</version>  
5 </dependency> 

以後就會添加三個包  slf4j-api-1.6.1.jar、slf4j-log4j12-1.7.2.jar、log4j-1.2.17.jarapp

 

2. 以後在項目下添加log4j.propertiesthis

 1 #config root logger  
 2 log4j.rootLogger = INFO,system.out  
 3 log4j.appender.system.out=org.apache.log4j.ConsoleAppender  
 4 log4j.appender.system.out.layout=org.apache.log4j.PatternLayout  
 5 log4j.appender.system.out.layout.ConversionPattern=MINAServer Logger-->%5p{%F:%L}-%m%n  
 6   
 7 #config this Project.file logger  
 8 log4j.logger.thisProject.file=INFO,thisProject.file.out  
 9 log4j.appender.thisProject.file.out=org.apache.log4j.DailyRollingFileAppender  
10 log4j.appender.thisProject.file.out.File=logContentFile.log  
11 log4j.appender.thisProject.file.out.layout=org.apache.log4j.PatternLayout

3. 在代碼中添加spa

private static final Logger logger = LoggerFactory.getLogger(MINAServer.class);  

 

若是要輸出到文件系統.net

 1 log4j.rootLogger=INFO,R,stdout    
 2     
 3 log4j.appender.stdout=org.apache.log4j.ConsoleAppender    
 4 log4j.appender.stdout.layout=org.apache.log4j.PatternLayout  
 5 log4j.appender.stdout.layout.ConversionPattern=Logger-->%5p{%F:%L}-%m%n   
 6     
 7 log4j.appender.R=org.apache.log4j.DailyRollingFileAppender    
 8 log4j.appender.R.File=../logs/log  
 9 log4j.appender.R.layout=org.apache.log4j.PatternLayout  
10 log4j.appender.R.layout.ConversionPattern=Logger-->%5p{%F:%L}-%m%n   

 

天天產生一個log的配置方法:code

log4j.rootLogger=DEBUG,DAILY_FILE
log4j.appender.DAILY_FILE=org.apache.log4j.DailyRollingFileAppender 
log4j.appender.DAILY_FILE.file=${user.home}/logs/logging.log4j
log4j.appender.DAILY_FILE.DatePattern='_'yyyy-MM-dd'.log' 
log4j.appender.DAILY_FILE.ImmediateFlush=true
log4j.appender.DAILY_FILE.Append=true
log4j.appender.DAILY_FILE.layout=org.apache.log4j.PatternLayout 
log4j.appender.DAILY_FILE.layout.ConversionPattern=%d %5p [%t] (%F:%L) - %m%n 

 

 

 轉載:http://blog.csdn.net/anialy/article/details/8529188xml

相關文章
相關標籤/搜索