为什么 Spring 日志消息看似没有错误却列为 [ERROR]?
我有一个 GWT/Spring 应用程序,使用 Maven 和 gwt-maven-plugin 构建。
当我运行
mvn gwt:run
gwt-maven-plugin 时,运行应用程序,一切都会启动并运行良好。令我困扰的是,即使没有明显的错误,日志消息也会在每一行上声明[ERROR],并且没有消息说明可能出现的错误。
我的猜测是,每个日志行上的 [ERROR] 来自 gwt-maven-plugin,因为后面的内容似乎是 Spring 的日志消息,如下所示...... [ERROR] INFO: 当我使用 mvn jetty:run 运行应用程序时,我只看到消息的 INFO: 部分。
附件是标准输出的大部分日志。有没有人见过这样的日志输出,或者对什么可能导致插件将信息消息记录为错误消息有任何想法?
[INFO] ------------------------------------------------------------------------
[INFO] Building GWT Maven Archetype 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> gwt-maven-plugin:2.4.0:run (default-cli) @ gwt >>>
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ gwt ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 10 resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ gwt ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-war-plugin:2.1.1:exploded (default) @ gwt ---
[INFO] Exploding webapp
[INFO] Assembling webapp [gwt] in [/home/jay/workspace/buildtimer/target/gwt-1.0- SNAPSHOT]
[INFO] Processing war project
[INFO] Copying webapp resources [/home/jay/workspace/buildtimer/src/main/webapp]
[INFO] Webapp assembled in [169 msecs]
[INFO]
[INFO] <<< gwt-maven-plugin:2.4.0:run (default-cli) @ gwt <<<
[INFO]
[INFO] --- gwt-maven-plugin:2.4.0:run (default-cli) @ gwt ---
[INFO] create exploded Jetty webapp in /home/jay/workspace/buildtimer/target/gwt-1.0- SNAPSHOT
[INFO] auto discovered modules [com.buildtimer.Main]
[ERROR] Nov 14, 2011 7:38:44 PM org.springframework.web.context.ContextLoader initWebApplicationContext
[ERROR] INFO: Root WebApplicationContext: initialization started
[ERROR] Nov 14, 2011 7:38:44 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
[ERROR] INFO: Refreshing Root WebApplicationContext: startup date [Mon Nov 14 19:38:44 EST 2011]; root of context hierarchy
[ERROR] Nov 14, 2011 7:38:44 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
[ERROR] INFO: Loading XML bean definitions from class path resource [META- INF/applicationContext.xml]
[ERROR] Nov 14, 2011 7:38:44 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
[ERROR] INFO: Loading XML bean definitions from class path resource [META- INF/applicationContext-persistence.xml]
[ERROR] Nov 14, 2011 7:38:44 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
[ERROR] INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1e42c6e: defining beans [org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.ann otation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.T ransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,tr ansactionManager,buildDao,dataSource,sessionFactory]; root of factory hierarchy
[ERROR] Nov 14, 2011 7:38:45 PM org.springframework.jdbc.datasource.DriverManagerDataSource setDriverClassName
[ERROR] INFO: Loaded JDBC driver: com.mysql.jdbc.Driver
[ERROR] SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
[ERROR] SLF4J: Defaulting to no-operation (NOP) logger implementation
[ERROR] SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
[ERROR] Nov 14, 2011 7:38:46 PM org.springframework.orm.hibernate3.LocalSessionFactoryBean buildSessionFactory
[ERROR] INFO: Building new Hibernate SessionFactory
[ERROR] Nov 14, 2011 7:38:48 PM org.springframework.orm.hibernate3.LocalSessionFactoryBean updateDatabaseSchema
[ERROR] INFO: Updating database schema for Hibernate SessionFactory
[ERROR] Nov 14, 2011 7:38:48 PM org.springframework.orm.hibernate3.HibernateTransactionManager afterPropertiesSet
[ERROR] INFO: Using DataSource [org.springframework.jdbc.datasource.DriverManagerDataSource@1b0e438] of Hibernate SessionFactory for HibernateTransactionManager
我的 web.xml 日志记录配置是
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
...
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/classes/log4j.properties.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
...
</web-app>
我的 log4j.properties.xml 文件
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="rootAppender" class="org.apache.log4j.FileAppender" >
<param name="file" value="app.log"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p %c - %m%n"/>
</layout>
</appender>
<root>
<priority value ="warn" />
<appender-ref ref="rootAppender" />
</root>
</log4j:configuration>
I have a GWT/Spring application, building with Maven and the gwt-maven-plugin.
When I run
mvn gwt:run
the gwt-maven-plugin runs the application and everything starts up and runs fine. What's bothering me is that the log messages claim [ERROR] on every line even though there are no apparent errors, and no message ever says what the error might be.
My guess is that [ERROR] on every log line is from the gwt-maven-plugin, since what comes after seems to be Spring's log message like so... [ERROR] INFO:
and when I run the app with mvn jetty:run, I see only the INFO: part of the messages.
Attached is most of the log to standard out. Has anybody seen log output like this, or have any ideas about what could cause a plugin to log info messages as error messages?
[INFO] ------------------------------------------------------------------------
[INFO] Building GWT Maven Archetype 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> gwt-maven-plugin:2.4.0:run (default-cli) @ gwt >>>
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ gwt ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 10 resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ gwt ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-war-plugin:2.1.1:exploded (default) @ gwt ---
[INFO] Exploding webapp
[INFO] Assembling webapp [gwt] in [/home/jay/workspace/buildtimer/target/gwt-1.0- SNAPSHOT]
[INFO] Processing war project
[INFO] Copying webapp resources [/home/jay/workspace/buildtimer/src/main/webapp]
[INFO] Webapp assembled in [169 msecs]
[INFO]
[INFO] <<< gwt-maven-plugin:2.4.0:run (default-cli) @ gwt <<<
[INFO]
[INFO] --- gwt-maven-plugin:2.4.0:run (default-cli) @ gwt ---
[INFO] create exploded Jetty webapp in /home/jay/workspace/buildtimer/target/gwt-1.0- SNAPSHOT
[INFO] auto discovered modules [com.buildtimer.Main]
[ERROR] Nov 14, 2011 7:38:44 PM org.springframework.web.context.ContextLoader initWebApplicationContext
[ERROR] INFO: Root WebApplicationContext: initialization started
[ERROR] Nov 14, 2011 7:38:44 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
[ERROR] INFO: Refreshing Root WebApplicationContext: startup date [Mon Nov 14 19:38:44 EST 2011]; root of context hierarchy
[ERROR] Nov 14, 2011 7:38:44 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
[ERROR] INFO: Loading XML bean definitions from class path resource [META- INF/applicationContext.xml]
[ERROR] Nov 14, 2011 7:38:44 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
[ERROR] INFO: Loading XML bean definitions from class path resource [META- INF/applicationContext-persistence.xml]
[ERROR] Nov 14, 2011 7:38:44 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
[ERROR] INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1e42c6e: defining beans [org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.ann otation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.T ransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,tr ansactionManager,buildDao,dataSource,sessionFactory]; root of factory hierarchy
[ERROR] Nov 14, 2011 7:38:45 PM org.springframework.jdbc.datasource.DriverManagerDataSource setDriverClassName
[ERROR] INFO: Loaded JDBC driver: com.mysql.jdbc.Driver
[ERROR] SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
[ERROR] SLF4J: Defaulting to no-operation (NOP) logger implementation
[ERROR] SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
[ERROR] Nov 14, 2011 7:38:46 PM org.springframework.orm.hibernate3.LocalSessionFactoryBean buildSessionFactory
[ERROR] INFO: Building new Hibernate SessionFactory
[ERROR] Nov 14, 2011 7:38:48 PM org.springframework.orm.hibernate3.LocalSessionFactoryBean updateDatabaseSchema
[ERROR] INFO: Updating database schema for Hibernate SessionFactory
[ERROR] Nov 14, 2011 7:38:48 PM org.springframework.orm.hibernate3.HibernateTransactionManager afterPropertiesSet
[ERROR] INFO: Using DataSource [org.springframework.jdbc.datasource.DriverManagerDataSource@1b0e438] of Hibernate SessionFactory for HibernateTransactionManager
My web.xml logging configuration is
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
...
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/classes/log4j.properties.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
...
</web-app>
my log4j.properties.xml file
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="rootAppender" class="org.apache.log4j.FileAppender" >
<param name="file" value="app.log"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p %c - %m%n"/>
</layout>
</appender>
<root>
<priority value ="warn" />
<appender-ref ref="rootAppender" />
</root>
</log4j:configuration>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不确定它有多少相关性,但您的日志表明 SLF4J 日志框架未正确初始化
确保您的 pom 中具有所有三个依赖项(SLF4J、log4j 绑定和 log4j 本身)
Not sure how much it is related, but your log indicates that the SLF4J logging framework is not properly initilaized
Make sure that you have all three dependencies in your pom (SLF4J, The log4j binding and log4j itself)