春天幕后记录

时间:2014-07-09 15:54:25

标签: spring spring-mvc log4j log4j2

我使用log4j2,我无法从春天登录。 当我自己编写logger.debug(...);时,它可以正常工作,但它与System.out.println(...);相同。

我想知道春天幕后发生了什么。显示创建的bean或debuggig错误,如400 ...

我试试这个Conf但没有发生任何事情:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
    <Appenders>
        <Console name="CONSOLE" target="SYSTEM_OUT">
            <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
        </Console>
    </Appenders>
    <Loggers>

        <Root level="ALL">
            <AppenderRef ref="CONSOLE"/>
        </Root>

        <logger name="org.springframework" level="ALL">
            <appender-ref ref="CONSOLE"/>
        </logger>


        <logger name="org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver"  level="ALL">
            <appender-ref ref="CONSOLE"/>
        </logger>

        <logger name="org.springframework.beans.factory.support.DefaultListableBeanFactory"  level="ALL">
            <appender-ref ref="CONSOLE"/>
        </logger>

    </Loggers>
</Configuration>

的pom.xml

<!-- log4j2 -->

<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-api</artifactId>
    <version>2.0-rc2</version>
</dependency>
<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <version>2.0-rc2</version>
</dependency>   
<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-web</artifactId>
    <version>2.0-rc2</version>
    <scope>runtime</scope>
</dependency>
<dependency>
     <groupId>org.apache.logging.log4j</groupId>
     <artifactId>log4j-jcl</artifactId>
     <version>2.0-rc2</version>
 </dependency>

启动日志:

juil. 09, 2014 4:42:57 PM org.apache.catalina.core.AprLifecycleListener init
Infos: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.7.0_45\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jre7/bin/client;C:/Program Files/Java/jre7/bin;C:/Program Files/Java/jre7/lib/i386;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Broadcom\Broadcom 802.11\Driver;D:\apache-maven-3.1.1\bin;C:\wamp\bin\mysql\mysql5.5.24\bin;C:\Program Files\Java\jdk1.7.0_45\bin;;D:\AO Project\eclipse;;.
juil. 09, 2014 4:42:57 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
Avertissement: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:AO' did not find a matching property.
juil. 09, 2014 4:42:57 PM org.apache.coyote.AbstractProtocol init
Infos: Initializing ProtocolHandler ["http-nio-8080"]
juil. 09, 2014 4:42:57 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
Infos: Using a shared selector for servlet write/read
juil. 09, 2014 4:42:57 PM org.apache.coyote.AbstractProtocol init
Infos: Initializing ProtocolHandler ["ajp-nio-8009"]
juil. 09, 2014 4:42:57 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
Infos: Using a shared selector for servlet write/read
juil. 09, 2014 4:42:57 PM org.apache.catalina.startup.Catalina load
Infos: Initialization processed in 670 ms
juil. 09, 2014 4:42:57 PM org.apache.catalina.core.StandardService startInternal
Infos: Démarrage du service Catalina
juil. 09, 2014 4:42:57 PM org.apache.catalina.core.StandardEngine startInternal
Infos: Starting Servlet Engine: Apache Tomcat/8.0.9
juil. 09, 2014 4:43:02 PM org.apache.catalina.core.ApplicationContext log
Infos: Log4jServletContainerInitializer starting up Log4j in Servlet 3.0+ environment.
juil. 09, 2014 4:43:03 PM org.apache.catalina.core.ApplicationContext log
Infos: No Spring WebApplicationInitializer types detected on classpath
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
juil. 09, 2014 4:43:03 PM org.apache.catalina.core.ApplicationContext log
Infos: Initializing Spring root WebApplicationContext
juil. 09, 2014 4:43:04 PM org.hibernate.jpa.internal.util.LogHelper logPersistenceUnitInformation
INFO: HHH000204: Processing PersistenceUnitInfo [
    name: persistenceYous
    ...]
juil. 09, 2014 4:43:05 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.3.5.Final}
juil. 09, 2014 4:43:05 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
juil. 09, 2014 4:43:05 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
juil. 09, 2014 4:43:06 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.4.Final}
juil. 09, 2014 4:43:06 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
juil. 09, 2014 4:43:07 PM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
juil. 09, 2014 4:43:11 PM org.apache.catalina.core.ApplicationContext log
Infos: Log4jServletContextListener ensuring that Log4j starts up properly.
juil. 09, 2014 4:43:11 PM org.apache.catalina.core.ApplicationContext log
Infos: Log4jServletFilter initialized.
juil. 09, 2014 4:43:11 PM org.apache.catalina.core.ApplicationContext log
Infos: Initializing Spring FrameworkServlet 'mvc-dispatcher'
juil. 09, 2014 4:43:13 PM org.apache.coyote.AbstractProtocol start
Infos: Starting ProtocolHandler ["http-nio-8080"]
juil. 09, 2014 4:43:13 PM org.apache.coyote.AbstractProtocol start
Infos: Starting ProtocolHandler ["ajp-nio-8009"]
juil. 09, 2014 4:43:13 PM org.apache.catalina.startup.Catalina start
Infos: Server startup in 15715 ms

1 个答案:

答案 0 :(得分:2)

问题解决了我认为错误来自于此

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

我必须将日志从slf4j路由到log4j,因为我认为Spring使用slf4j进行日志记录所以我添加了log4j-slf4j-impl jar,最后它可以正常工作: - )

    <dependency> 
         <groupId>org.apache.logging.log4j</groupId>
         <artifactId>log4j-slf4j-impl</artifactId>
         <version>2.0-rc2</version>
     </dependency> 

PS:为什么我认为Spring使用slf4j代替 common logging ,因为我添加log4j-jcl jar但没有任何事情发生。

    <dependency> 
         <groupId>org.apache.logging.log4j</groupId>
         <artifactId>log4j-jcl</artifactId>
         <version>2.0-rc2</version>
     </dependency>