2017-11-27 10 views
0

진열대에서 봄 부트 템플릿 : spring-boot-starter-log4j2, spring-boot-starter-webspring-boot-starter-actuator.왜 스프링 로거가 org.springframework에서 상속되지 않는가?

나는 log4j2가 WARN 이상인 경우 Spring 관련 메시지 만 기록하려고합니다. 나머지는 DEBUG 이상을 기록하고 싶습니다.

Log4j2의 설정은 다음과 같습니다

<Configuration status="DEBUG"> 
    <Appenders> 
     <Console name="STDERR" target="SYSTEM_ERR"> 
      <PatternLayout> 
       <pattern>%highlight{[%level]} %logger %message %throwable%n</pattern> 
      </PatternLayout> 
     </Console> 
    </Appenders> 

    <Loggers> 
     <Logger name="org.springframework" level="warn" /> 

     <Root level="debug"> 
      <AppenderRef ref="STDERR"/> 
     </Root> 
    </Loggers> 
</Configuration> 

를 작동하지 않는 몇 가지 이유 : org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMappingSTDERR에 추가합니다. 따라서 org.springframework.boot.web.servlet.FilterRegistrationBean, org.springframework.boot.logging.ClasspathLoggingApplicationListener 및 기타 여러 가지가 있습니다.

org.springframework.boot.actuate.endpoint.mvc, org.springframework.boot.web.servlet, org.springframework.boot.logging 등의 레벨을 수동으로 설정할 수 있습니다. 왜 그런지는 알 수 없습니다.

로거 설정은 org.springframework 로거 설정에 바인드되어 있고 레벨이 WARN입니다.

Log4j의 진단 출력 :

21:03:58,102 Loaded configuration from /src/SpringBootLoggingTest/log-configuration/log4j2-desktop.xml 
21:03:58,103 Starting LoggerContext[name=42a57993, [email protected]] with configuration XmlConfiguration[location=/src/SpringBootLoggingTest/log-configuration/log4j2-desktop.xml]... 
21:03:58,104 Initializing configuration XmlConfiguration[location=/src/SpringBootLoggingTest/log-configuration/log4j2-desktop.xml] 
21:03:58,105 Installed script engines 
21:03:58,120 Oracle Nashorn Version: 1.8.0_152, Language: ECMAScript, Threading: Not Thread Safe, Compile: true, Names: {nashorn, Nashorn, js, JS, JavaScript, javascript, ECMAScript, ecmascript} 
21:03:58,120 PluginManager 'Core' found 110 plugins 
21:03:58,120 PluginManager 'Level' found 0 plugins 
21:03:58,123 Log4j2 ConfigurationScheduler: No scheduled items 
21:03:58,123 PluginManager 'Lookup' found 13 plugins 
21:03:58,124 Building Plugin[name=layout, class=org.apache.logging.log4j.core.layout.PatternLayout]. 
21:03:58,131 PluginManager 'TypeConverter' found 23 plugins 
21:03:58,138 PatternLayout$Builder(pattern="%highlight{[%level]} %logger %message %throwable%n", PatternSelector=null, Configuration(/src/SpringBootLoggingTest/log-configuration/log4j2-desktop.xml), Replace=null, charset="null", alwaysWriteExceptions="null", noConsoleNoAnsi="null", header="null", footer="null") 
21:03:58,139 PluginManager 'Converter' found 44 plugins 
21:03:58,141 Building Plugin[name=appender, class=org.apache.logging.log4j.core.appender.ConsoleAppender]. 
21:03:58,147 ConsoleAppender$Builder(target="SYSTEM_ERR", follow="null", direct="null", bufferedIo="null", bufferSize="null", immediateFlush="null", ignoreExceptions="null", PatternLayout(%highlight{[%level]} %logger %message %throwable%n), name="STDERR", Filter=null) 
21:03:58,147 Starting OutputStreamManager SYSTEM_ERR.false.false 
21:03:58,147 Building Plugin[name=appenders, class=org.apache.logging.log4j.core.config.AppendersPlugin]. 
21:03:58,148 createAppenders(={STDERR}) 
21:03:58,149 Building Plugin[name=logger, class=org.apache.logging.log4j.core.config.LoggerConfig]. 
21:03:58,154 createLogger(additivity="true", level="WARN", name="org.springframework", includeLocation="null", ={}, ={}, Configuration(/src/SpringBootLoggingTest/log-configuration/log4j2-desktop.xml), Filter=null) 
21:03:58,155 Building Plugin[name=AppenderRef, class=org.apache.logging.log4j.core.config.AppenderRef]. 
21:03:58,155 createAppenderRef(ref="STDERR", level="null", Filter=null) 
21:03:58,156 Building Plugin[name=root, class=org.apache.logging.log4j.core.config.LoggerConfig$RootLogger]. 
21:03:58,156 createLogger(additivity="null", level="DEBUG", includeLocation="null", ={STDERR}, ={}, Configuration(/src/SpringBootLoggingTest/log-configuration/log4j2-desktop.xml), Filter=null) 
21:03:58,157 Building Plugin[name=loggers, class=org.apache.logging.log4j.core.config.LoggersPlugin]. 
21:03:58,157 createLoggers(={org.springframework, root}) 
21:03:58,158 Configuration XmlConfiguration[location=/src/SpringBootLoggingTest/log-configuration/log4j2-desktop.xml] initialized 
21:03:58,158 Starting configuration XmlConfiguration[location=/src/SpringBootLoggingTest/log-configuration/log4j2-desktop.xml] 
21:03:58,158 Started configuration XmlConfiguration[location=/src/SpringBootLoggingTest/log-configuration/log4j2-desktop.xml] OK. 
21:03:58,159 Shutting down OutputStreamManager SYSTEM_OUT.false.false-2 
21:03:58,159 Shut down OutputStreamManager SYSTEM_OUT.false.false-2, all resources released: true 
21:03:58,159 Stopped [email protected]9c OK 
21:03:58,162 Registering MBean org.apache.logging.log4j2:type=42a57993 
21:03:58,163 Registering MBean org.apache.logging.log4j2:type=42a57993,component=StatusLogger 
21:03:58,163 Registering MBean org.apache.logging.log4j2:type=42a57993,component=ContextSelector 
21:03:58,164 Registering MBean org.apache.logging.log4j2:type=42a57993,component=Loggers,name= 
21:03:58,165 Registering MBean org.apache.logging.log4j2:type=42a57993,component=Loggers,name=org.springframework 
21:03:58,165 Registering MBean org.apache.logging.log4j2:type=42a57993,component=Appenders,name=STDERR 
21:03:58,165 LoggerContext[name=42a57993, [email protected]] started OK with configuration XmlConfiguration[location=/src/SpringBootLoggingTest/log-configuration/log4j2-desktop.xml]. 
21:03:58,173 AsyncLogger.ThreadNameStrategy=CACHED 

답변

0

당신이 logger 구성 아래로 사용해 볼 수 -

<Loggers> 
    <Logger name="org.springframework" level="warn" additivity="false"> 
     <AppenderRef ref="STDERR" /> 
    </Logger> 
    <Root level="debug" additivity="false"> 
     <AppenderRef ref="STDERR" /> 
    </Root> 
</Loggers>