slf4j+log4j配置(Maven)

  • 首先配置Maven依赖
<!-- http://mvnrepository.com/artifact/org.slf4j/slf4j-log4j12 -->
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
    <version>1.7.21</version>
</dependency>
View Code
  • 代码目录添加log4j.properties配置文件
#config root logger
log4j.rootLogger = INFO,system.out
log4j.appender.system.out=org.apache.log4j.ConsoleAppender
log4j.appender.system.out.layout=org.apache.log4j.PatternLayout
log4j.appender.system.out.layout.ConversionPattern=LuceneServer Logger-->%5p{%F:%L}-%m%n

#config this Project.file logger
log4j.logger.thisProject.file=INFO,thisProject.file.out
log4j.appender.thisProject.file.out=org.apache.log4j.DailyRollingFileAppender
log4j.appender.thisProject.file.out.File=logContentFile.log
log4j.appender.thisProject.file.out.layout=org.apache.log4j.PatternLayout
View Code
  • 代码引入
private static final Logger logger = LoggerFactory.getLogger(SeachTest.class);

 

posted @ 2016-05-23 20:12  指尖挥舞  阅读(731)  评论(0编辑  收藏  举报