我无法让使用 slf4j 进行日志记录的配置正常工作。错误日志如下所示
INFO: visiting unvisited references
SEVERE: log4j:ERROR A "org.apache.log4j.ConsoleAppender" object is not assignable to a "org.apache.log4j.Appender" variable.
SEVERE: log4j:ERROR The class "org.apache.log4j.Appender" was loaded by
SEVERE: log4j:ERROR [WebappClassLoader (delegate=true; repositories=WEB-INF/classes/)] whereas object of type
SEVERE: log4j:ERROR "org.apache.log4j.ConsoleAppender" was loaded by [WebappClassLoader (delegate=true; repositories=WEB-INF/classes/)].
SEVERE: log4j:ERROR Could not instantiate appender named "stdout".
SEVERE: log4j:ERROR A "org.apache.log4j.DailyRollingFileAppender" object is not assignable to a "org.apache.log4j.Appender" variable.
SEVERE: log4j:ERROR The class "org.apache.log4j.Appender" was loaded by
SEVERE: log4j:ERROR [WebappClassLoader (delegate=true; repositories=WEB-INF/classes/)] whereas object of type
SEVERE: log4j:ERROR "org.apache.log4j.DailyRollingFileAppender" was loaded by [WebappClassLoader (delegate=true; repositories=WEB-INF/classes/)].
SEVERE: log4j:ERROR Could not instantiate appender named "file".
SEVERE: log4j:WARN No appenders could be found for logger (org.hibernate.annotations.common.Version).
SEVERE: log4j:WARN Please initialize the log4j system properly.
INFO: WebModule[null] ServletContext.log():No Spring WebApplicationInitializer types detected on classpath
WARNING: JSF1022: [true/false] Invalid value 'javax.faces.PARTIAL_STATE_SAVING' for configuration option 'true|false'. Valid values are 'true|false'. Falling back to the default of 'true'.
INFO: Initializing Mojarra 2.2.0 ( 20130502-2118 https://svn.java.net/svn/mojarra~svn/tags/2.2.0@11930) for context '/AnchorFused4.03'
INFO: Monitoring jndi:/server/.../WEB-INF/faces-config.xml for modifications
我已经设置了以下依赖项
<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
我也有hibernate和spring依赖
项我已经从依赖项中排除了commons-logging以避免任何冲突......
log4j 属性文件位于 src/main/resources 中,它位于 WEB-INF/classes/ 类路径下。
#Log to Console as STDOUT
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{yyyy-MM-dd HH:mm:ss} %-5p %c %3x - %m%n
#Log to file FILE
log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
log4j.appender.file.File=logfile.log
log4j.appender.file.DatePattern='.'yyyy-MM-dd
log4j.appender.file.append=true
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c %3x - %m%n
#Root Logger
log4j.rootLogger=INFO, stdout, file
我已经尝试了几种与 slf4j-log4j12 和 slf4j-simple 的组合,它们各自独立使用,但都产生相同的错误。
注意:我注意到,如果我从 maven 依赖项中排除 jboss-logging,我不会收到 Log4j 错误。但不幸的是,jboss-logging 是一种休眠核心依赖项,没有它,应用程序将无法运行。