복붙노트

[SPRING] 로깅 뒤에서 봄

SPRING

로깅 뒤에서 봄

내가 log4j2를 사용하고 나는 봄에서 로깅을 얻을 수 없습니다. 내 자신의 logger.debug (...); 작동하지만 System.out.println (...);과 같습니다.

나는 봄에 무슨 일이 일어 났는지 알고 싶다. 생성 된 빈을 표시하거나 오류 라인 400을 디버깅 ...

이 회의를 시도했지만 아무 일도 없었습니다.

<?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.hml

<!-- 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. ==============================

    1.문제가 해결되었습니다.이 오류는이 오류에서 비롯된 것 같습니다.

    문제가 해결되었습니다.이 오류는이 오류에서 비롯된 것 같습니다.

    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로 로그를 보내야한다. 왜냐하면 스프링은 로깅을 위해 slf4j를 사용한다. 그래서 log4j-slf4j-impl jar를 추가하고 마침내 작동한다 :-)

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

    추신 : 왜냐하면 나는 log4j-jcl jar를 추가했기 때문에 Spring은 일반적인 로깅 대신 slf4j를 사용한다고 생각하지만 아무 일도 일어나지 않았습니다.

        <dependency> 
             <groupId>org.apache.logging.log4j</groupId>
             <artifactId>log4j-jcl</artifactId>
             <version>2.0-rc2</version>
         </dependency> 
    
  2. from https://stackoverflow.com/questions/24658384/spring-behind-the-scenes-logging by cc-by-sa and MIT license