正确的依赖

 <!-- slf4j 依赖包 -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.25</version>
</dependency>
#这个是自己项目中使用的一个配置,方便拿来直接使用。简单的配置,如果想要添加详细配置需要去找资料,看一下log4j的具体参数配,这里暂时没有。

log4j.rootLogger=info,consoleLog,logfile

# Console output...
log4j.appender.consoleLog=org.apache.log4j.ConsoleAppender
log4j.appender.consoleLog.layout=org.apache.log4j.PatternLayout
log4j.appender.consoleLog.layout.ConversionPattern=[%p]-%-d{HH:mm:ss}-%c{1} - %m%n # file output...error one day
log4j.appender.logfile=org.apache.log4j.DailyRollingFileAppender
log4j.appender.logfile.DatePattern='.'yyyy-MM-dd'.log'
log4j.appender.logfile.File=${catalina.base}/jfinal_mac.log
log4j.appender.logfile.Threshold = error
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern= [%p]-%-d{HH:mm:ss}-%c{1} - %m%n # file output...info every hour
log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
log4j.appender.D.DatePattern='.'yyyy-MM-dd-HH'.log'
log4j.appender.D.File = ${catalina.base}/logs/jfinal_mac.txt
log4j.appender.D.Append = true
log4j.appender.D.Threshold = info
log4j.appender.D.layout = org.apache.log4j.PatternLayout
log4j.appender.D.layout.ConversionPattern = [%p]-%-d{HH\:mm\:ss}-%c{1} - %m%n

以下在配置时候出现的问题:

可能有的依赖版本不同,导致直接默认使用的式log4j2.xml  或  log4j2.json

启动是出现过问题:

ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console. Set system property 'log4j2.debug' to show Log4j2 internal initialization logging.

使用的依赖是一下的:

<!-- slf4j 依赖包 -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.9.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.9.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.9.1</version>
</dependency> 不太清楚这几个依赖怎么搭配,记录一下,最上边的是可以使用的,复制直接使用就可以了。
05-11 15:41