为什么我的INFO日志在关闭时仍然会被记录?

时间:2016-04-14 13:38:11

标签: java logging log4j2

我刚刚意识到我们正在使用log4j2并且我的log4j属性文件没有被使用。所以我放入了最基本的log4j2.xml文件来验证它的使用情况。我希望看到我的日志都没有关闭,而是看到所有。任何人都可以向我指出为什么水平集不被尊重?

这是我的档案:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="trace" packages="">
  <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="off">
      <AppenderRef ref="Console"/>
    </Root>
  </Loggers>
</Configuration>

Log4j启动跟踪日志:

2016-04-14 10:40:26,916 localhost-startStop-1 DEBUG Initializing configuration XmlConfiguration[location=C:\Workspaces\Q1Workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\TestLicense\WEB-INF\classes\log4j2.xml]
2016-04-14 10:40:26,924 localhost-startStop-1 DEBUG Installed script engines
2016-04-14 10:40:27,325 localhost-startStop-1 DEBUG Oracle Nashorn Version: 1.8.0_72, Language: ECMAScript, Threading: Not Thread Safe, Compile: true, Names: {nashorn, Nashorn, js, JS, JavaScript, javascript, ECMAScript, ecmascript}
2016-04-14 10:40:27,326 localhost-startStop-1 DEBUG PluginManager 'Core' found 97 plugins
2016-04-14 10:40:27,326 localhost-startStop-1 DEBUG PluginManager 'Level' found 0 plugins
2016-04-14 10:40:27,329 localhost-startStop-1 DEBUG No scheduled items
2016-04-14 10:40:27,330 localhost-startStop-1 DEBUG PluginManager 'Lookup' found 13 plugins
2016-04-14 10:40:27,332 localhost-startStop-1 DEBUG Building Plugin[name=layout, class=org.apache.logging.log4j.core.layout.PatternLayout].
2016-04-14 10:40:27,343 localhost-startStop-1 TRACE TypeConverterRegistry initializing.
2016-04-14 10:40:27,344 localhost-startStop-1 DEBUG PluginManager 'TypeConverter' found 23 plugins
2016-04-14 10:40:27,357 localhost-startStop-1 DEBUG PatternLayout$Builder(pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n", PatternSelector=null, Configuration(C:\Workspaces\Q1Workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\TestLicense\WEB-INF\classes\log4j2.xml), Replace=null, charset="null", alwaysWriteExceptions="null", noConsoleNoAnsi="null", header="null", footer="null")
2016-04-14 10:40:27,357 localhost-startStop-1 DEBUG PluginManager 'Converter' found 38 plugins
2016-04-14 10:40:27,358 localhost-startStop-1 DEBUG Building Plugin[name=appender, class=org.apache.logging.log4j.core.appender.ConsoleAppender].
2016-04-14 10:40:27,360 localhost-startStop-1 INFO Log4j appears to be running in a Servlet environment, but there's no log4j-web module available. If you want better web container support, please add the log4j-web JAR to your web archive or server lib directory.
2016-04-14 10:40:27,361 localhost-startStop-1 DEBUG PluginManager 'Converter' found 38 plugins
2016-04-14 10:40:27,362 localhost-startStop-1 DEBUG Jansi is not installed, cannot find org.fusesource.jansi.WindowsAnsiOutputStream
2016-04-14 10:40:27,363 localhost-startStop-1 DEBUG Starting OutputStreamManager SYSTEM_OUT.false-2
2016-04-14 10:40:27,368 localhost-startStop-1 DEBUG ConsoleAppender$Builder(PatternLayout(%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n), Filter=null, target="SYSTEM_OUT", name="Console", follow="null", ignoreExceptions="null")
2016-04-14 10:40:27,368 localhost-startStop-1 DEBUG Jansi is not installed, cannot find org.fusesource.jansi.WindowsAnsiOutputStream
2016-04-14 10:40:27,368 localhost-startStop-1 DEBUG Starting OutputStreamManager SYSTEM_OUT.false
2016-04-14 10:40:27,368 localhost-startStop-1 DEBUG Building Plugin[name=appenders, class=org.apache.logging.log4j.core.config.AppendersPlugin].
2016-04-14 10:40:27,368 localhost-startStop-1 DEBUG createAppenders(={Console})
2016-04-14 10:40:27,368 localhost-startStop-1 DEBUG Building Plugin[name=AppenderRef, class=org.apache.logging.log4j.core.config.AppenderRef].
2016-04-14 10:40:27,368 localhost-startStop-1 DEBUG createAppenderRef(ref="Console", level="null", Filter=null)
2016-04-14 10:40:27,368 localhost-startStop-1 DEBUG Building Plugin[name=root, class=org.apache.logging.log4j.core.config.LoggerConfig$RootLogger].
2016-04-14 10:40:27,368 localhost-startStop-1 DEBUG createLogger(additivity="null", level="OFF", includeLocation="null", ={Console}, ={}, Configuration(C:\Workspaces\Q1Workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\TestLicense\WEB-INF\classes\log4j2.xml), Filter=null)
2016-04-14 10:40:27,385 localhost-startStop-1 DEBUG Building Plugin[name=loggers, class=org.apache.logging.log4j.core.config.LoggersPlugin].
2016-04-14 10:40:27,386 localhost-startStop-1 DEBUG createLoggers(={root})
2016-04-14 10:40:27,387 localhost-startStop-1 DEBUG Configuration XmlConfiguration[location=C:\Workspaces\Q1Workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\TestLicense\WEB-INF\classes\log4j2.xml] initialized
2016-04-14 10:40:27,387 localhost-startStop-1 DEBUG Starting configuration XmlConfiguration[location=C:\Workspaces\Q1Workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\TestLicense\WEB-INF\classes\log4j2.xml]
2016-04-14 10:40:27,387 localhost-startStop-1 DEBUG Started configuration XmlConfiguration[location=C:\Workspaces\Q1Workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\TestLicense\WEB-INF\classes\log4j2.xml] OK.
2016-04-14 10:40:27,388 localhost-startStop-1 TRACE Stopping org.apache.logging.log4j.core.config.DefaultConfiguration@19789652...
2016-04-14 10:40:27,388 localhost-startStop-1 TRACE DefaultConfiguration notified 1 ReliabilityStrategies that config will be stopped.
2016-04-14 10:40:27,388 localhost-startStop-1 TRACE DefaultConfiguration stopping root LoggerConfig.
2016-04-14 10:40:27,388 localhost-startStop-1 TRACE DefaultConfiguration notifying ReliabilityStrategies that appenders will be stopped.
2016-04-14 10:40:27,389 localhost-startStop-1 TRACE DefaultConfiguration stopping remaining Appenders.
2016-04-14 10:40:27,389 localhost-startStop-1 DEBUG Shutting down OutputStreamManager SYSTEM_OUT.false-1
2016-04-14 10:40:27,389 localhost-startStop-1 TRACE DefaultConfiguration stopped 1 remaining Appenders.
2016-04-14 10:40:27,389 localhost-startStop-1 TRACE DefaultConfiguration cleaning Appenders from 1 LoggerConfigs.
2016-04-14 10:40:27,390 localhost-startStop-1 DEBUG Stopped org.apache.logging.log4j.core.config.DefaultConfiguration@19789652 OK
2016-04-14 10:40:27,392 localhost-startStop-1 TRACE Reregistering MBeans after reconfigure. Selector=org.apache.logging.log4j.core.selector.ClassLoaderContextSelector@59c13ee7
2016-04-14 10:40:27,393 localhost-startStop-1 TRACE Reregistering context (1/1): '535ee47f' org.apache.logging.log4j.core.LoggerContext@48b37677
2016-04-14 10:40:27,394 localhost-startStop-1 TRACE Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=535ee47f'
2016-04-14 10:40:27,394 localhost-startStop-1 TRACE Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=535ee47f,component=StatusLogger'
2016-04-14 10:40:27,394 localhost-startStop-1 TRACE Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=535ee47f,component=ContextSelector'
2016-04-14 10:40:27,395 localhost-startStop-1 TRACE Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=535ee47f,component=Loggers,name=*'
2016-04-14 10:40:27,395 localhost-startStop-1 TRACE Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=535ee47f,component=Appenders,name=*'
2016-04-14 10:40:27,395 localhost-startStop-1 TRACE Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=535ee47f,component=AsyncAppenders,name=*'
2016-04-14 10:40:27,396 localhost-startStop-1 TRACE Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=535ee47f,component=AsyncLoggerRingBuffer'
2016-04-14 10:40:27,396 localhost-startStop-1 TRACE Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=535ee47f,component=Loggers,name=*,subtype=RingBuffer'
2016-04-14 10:40:27,398 localhost-startStop-1 DEBUG Registering MBean org.apache.logging.log4j2:type=535ee47f
2016-04-14 10:40:27,402 localhost-startStop-1 DEBUG Registering MBean org.apache.logging.log4j2:type=535ee47f,component=StatusLogger
2016-04-14 10:40:27,405 localhost-startStop-1 DEBUG Registering MBean org.apache.logging.log4j2:type=535ee47f,component=ContextSelector
2016-04-14 10:40:27,407 localhost-startStop-1 DEBUG Registering MBean org.apache.logging.log4j2:type=535ee47f,component=Loggers,name=
2016-04-14 10:40:27,410 localhost-startStop-1 DEBUG Registering MBean org.apache.logging.log4j2:type=535ee47f,component=Appenders,name=Console
2016-04-14 10:40:27,416 localhost-startStop-1 TRACE Using default SystemClock for timestamps.
2016-04-14 10:40:27,418 localhost-startStop-1 TRACE Using DummyNanoClock for nanosecond timestamps.
2016-04-14 10:40:27,418 localhost-startStop-1 DEBUG Reconfiguration complete for context[name=535ee47f] at URI C:\Workspaces\Q1Workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\TestLicense\WEB-INF\classes\log4j2.xml (org.apache.logging.log4j.core.LoggerContext@48b37677) with optional ClassLoader: null

请在此处继续记录来自我的应用程序的信息:

Apr 14, 2016 12:02:46 PM com.myorg.licensing.persistence.dao.ext.S1ProductDaoExt update
INFO: updating S1Product instance
Apr 14, 2016 12:02:46 PM com.myorg.licensing.persistence.dao.ext.S1ProductDaoExt update
INFO: update successful
Apr 14, 2016 12:02:52 PM com.myorg.licensing.persistence.dao.ext.S1ProductDaoExt update
INFO: updating S1Product instance
Apr 14, 2016 12:02:52 PM com.myorg.licensing.persistence.dao.ext.S1ProductDaoExt update
INFO: update successful
Apr 14, 2016 12:02:56 PM com.myorg.licensing.persistence.dao.ext.S1ProductDaoExt update
INFO: updating S1Product instance
Apr 14, 2016 12:02:56 PM com.myorg.licensing.persistence.dao.ext.S1ProductDaoExt update
INFO: update successful

1 个答案:

答案 0 :(得分:0)

我的hibernate模型正在从数据库进行逆向工程,并使用org.apache.commons.logging.Log和org.apache.commons.logging.LogFactory而不是相应的Log4j2类生成。

上面的Log4j2配置确实关闭了我的所有内部Log4j2日志,它仍然是附加到控制台的Apache公共日志。