2017-11-27 8 views
0

Springブートテンプレートオフフック:spring-boot-starter-log4j2spring-boot-starter-webおよびspring-boot-starter-actuatorなぜSpringロガーがorg.springframeworkから継承されないのですか

私はlog4j2が、WARN以上であれば、Spring関連のメッセージのみをログに記録しようとしています。残りの部分については、DEBUG以上を記録したいと思います。それが動作しないいくつかの理由について

<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> 

Log4j2の設定は次のようになりますorg.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMappingSTDERRに追加します。だからorg.springframework.boot.web.servlet.FilterRegistrationBeanorg.springframework.boot.logging.ClasspathLoggingApplicationListenerなど多くのものがあります。

私は手動でorg.springframework.boot.actuate.endpoint.mvcorg.springframework.boot.web.servletorg.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> 
関連する問題