2016-07-19 43 views
0

令人惊讶的是log4j2在线程中执行时不会打印消息。log4j2不会打印在线程中触发的消息

详细

  • log4j2版本2.6.2
  • 调试和运行的影响
  • 两个标准追加程序(文件,控制台)
  • 电话像LOG.error("msg");LOG.error("msg", e);LOG.info("bad news", e);
  • 运行在sepa率线程以及所有后续日志调用并不代表
  • Eclipse的火星版本(4.5.0)
  • 的Java JDK 1.8.0_51
  • Maven的3.x的项目,但发射出去的Eclipse
  • Win 7的(专业)

初始化

private static final Logger LOG = LogManager.getLogger(MainProcess.class);

配置

<?xml version="1.0" encoding="UTF-8"?> 
<Configuration xmlns="http://logging.apache.org/log4j/2.0/config" packages="xyz.my.appenders"> 
<Appenders> 
    <File name="file" fileName="logfile.log" append="true"> 
     <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] [%p] %C{2} (%F:%L) - %m%n"/> 
    </File> 
    <Console name="console" target="SYSTEM_OUT"> 
     <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] [%p] %C{2} (%F:%L) - %m%n"/> 
    </Console> 
    <LimitAppender name="log-viewer" numberOfLines="30"> 
     <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] [%p] %C{2} (%F:%L) - %m%n"/> 
    </LimitAppender> 
</Appenders> 
<Loggers> 
    <Logger name="xyz.my.application" level="DEBUG"/> 
    <Root level="DEBUG"> 
     <AppenderRef ref="console"/> 
     <AppenderRef ref="file"/> 
     <!-- <AppenderRef ref="log-viewer"/> --> 
    </Root> 
</Loggers> 
</Configuration> 

跟踪log4j2的(283 200行)

2016-07-20 09:42:14,396 main DEBUG Initializing configuration XmlConfiguration[location=C:\...\TheProject\target\classes\log4j2.xml] 
2016-07-20 09:42:14,409 main DEBUG Installed script engines 
2016-07-20 09:42:15,040 main DEBUG Oracle Nashorn Version: 1.8.0_51, Language: ECMAScript, Threading: Not Thread Safe, Compile: true, Names: {nashorn, Nashorn, js, JS, JavaScript, javascript, ECMAScript, ecmascript} 
2016-07-20 09:42:15,115 main DEBUG Took 0.074225 seconds to load 1 plugins from package xyz.my.appenders 
2016-07-20 09:42:15,115 main DEBUG PluginManager 'Core' found 100 plugins 
2016-07-20 09:42:15,116 main DEBUG PluginManager 'Level' found 0 plugins 
2016-07-20 09:42:15,119 main DEBUG No scheduled items 
2016-07-20 09:42:15,119 main DEBUG PluginManager 'Lookup' found 13 plugins 
2016-07-20 09:42:15,121 main DEBUG Building Plugin[name=layout, class=org.apache.logging.log4j.core.layout.PatternLayout]. 
2016-07-20 09:42:15,132 main TRACE TypeConverterRegistry initializing. 
2016-07-20 09:42:15,132 main DEBUG PluginManager 'TypeConverter' found 23 plugins 
2016-07-20 09:42:15,144 main DEBUG PatternLayout$Builder(pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] [%p] %C{2} (%F:%L) - %m%n", PatternSelector=null, Configuration(C:\...\TheProject\target\classes\log4j2.xml), Replace=null, charset="null", alwaysWriteExceptions="null", noConsoleNoAnsi="null", header="null", footer="null") 
2016-07-20 09:42:15,145 main DEBUG PluginManager 'Converter' found 41 plugins 
2016-07-20 09:42:15,179 main DEBUG Building Plugin[name=appender, class=org.apache.logging.log4j.core.appender.FileAppender]. 
2016-07-20 09:42:15,185 main DEBUG createAppender(fileName="logfile.log", append="true", locking="null", name="file", immediateFlush="null", ignoreExceptions="null", bufferedIo="null", bufferSize="null", PatternLayout(%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] [%p] %C{2} (%F:%L) - %m%n), Filter=null, advertise="null", advertiseUri="null", Configuration(C:\...\TheProject\target\classes\log4j2.xml)) 
2016-07-20 09:42:15,189 main DEBUG Starting FileManager logfile.log 
2016-07-20 09:42:15,189 main DEBUG Building Plugin[name=layout, class=org.apache.logging.log4j.core.layout.PatternLayout]. 
2016-07-20 09:42:15,190 main DEBUG PatternLayout$Builder(pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] [%p] %C{2} (%F:%L) - %m%n", PatternSelector=null, Configuration(C:\...\TheProject\target\classes\log4j2.xml), Replace=null, charset="null", alwaysWriteExceptions="null", noConsoleNoAnsi="null", header="null", footer="null") 
2016-07-20 09:42:15,190 main DEBUG Building Plugin[name=appender, class=org.apache.logging.log4j.core.appender.ConsoleAppender]. 
2016-07-20 09:42:15,192 main DEBUG Not in a ServletContext environment, thus not loading WebLookup plugin. 
2016-07-20 09:42:15,193 main DEBUG PluginManager 'Converter' found 41 plugins 
2016-07-20 09:42:15,194 main DEBUG Jansi is not installed, cannot find org.fusesource.jansi.WindowsAnsiOutputStream 
2016-07-20 09:42:15,194 main DEBUG Starting OutputStreamManager SYSTEM_OUT.false-2 
2016-07-20 09:42:15,202 main DEBUG ConsoleAppender$Builder(PatternLayout(%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] [%p] %C{2} (%F:%L) - %m%n), Filter=null, target="SYSTEM_OUT", name="console", follow="null", ignoreExceptions="null") 
2016-07-20 09:42:15,203 main DEBUG Jansi is not installed, cannot find org.fusesource.jansi.WindowsAnsiOutputStream 
2016-07-20 09:42:15,204 main DEBUG Starting OutputStreamManager SYSTEM_OUT.false 
2016-07-20 09:42:15,204 main DEBUG Building Plugin[name=layout, class=org.apache.logging.log4j.core.layout.PatternLayout]. 
2016-07-20 09:42:15,204 main DEBUG PatternLayout$Builder(pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] [%p] %C{2} (%F:%L) - %m%n", PatternSelector=null, Configuration(C:\...\TheProject\target\classes\log4j2.xml), Replace=null, charset="null", alwaysWriteExceptions="null", noConsoleNoAnsi="null", header="null", footer="null") 
2016-07-20 09:42:15,205 main DEBUG Building Plugin[name=appender, class=xyz.my.appenders.LimitMemoryAppender]. 
2016-07-20 09:42:15,205 main DEBUG createAppender(name="log-viewer", PatternLayout(%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] [%p] %C{2} (%F:%L) - %m%n), numberOfLines="30") 
2016-07-20 09:42:15,206 main DEBUG Building Plugin[name=appenders, class=org.apache.logging.log4j.core.config.AppendersPlugin]. 
2016-07-20 09:42:15,207 main DEBUG createAppenders(={file, console, log-viewer}) 
2016-07-20 09:42:15,207 main DEBUG Building Plugin[name=logger, class=org.apache.logging.log4j.core.config.LoggerConfig]. 
2016-07-20 09:42:15,210 main DEBUG createLogger(additivity="true", level="DEBUG", name="xyz.my.project", includeLocation="null", ={}, ={}, Configuration(C:\...\TheProject\target\classes\log4j2.xml), Filter=null) 
2016-07-20 09:42:15,213 main DEBUG Building Plugin[name=AppenderRef, class=org.apache.logging.log4j.core.config.AppenderRef]. 
2016-07-20 09:42:15,214 main DEBUG createAppenderRef(ref="console", level="null", Filter=null) 
2016-07-20 09:42:15,214 main DEBUG Building Plugin[name=AppenderRef, class=org.apache.logging.log4j.core.config.AppenderRef]. 
2016-07-20 09:42:15,214 main DEBUG createAppenderRef(ref="file", level="null", Filter=null) 
2016-07-20 09:42:15,214 main DEBUG Building Plugin[name=AppenderRef, class=org.apache.logging.log4j.core.config.AppenderRef]. 
2016-07-20 09:42:15,215 main DEBUG createAppenderRef(ref="log-viewer", level="null", Filter=null) 
2016-07-20 09:42:15,215 main DEBUG Building Plugin[name=root, class=org.apache.logging.log4j.core.config.LoggerConfig$RootLogger]. 
2016-07-20 09:42:15,216 main DEBUG createLogger(additivity="null", level="DEBUG", includeLocation="null", ={console, file, log-viewer}, ={}, Configuration(C:\...\TheProject\target\classes\log4j2.xml), Filter=null) 
2016-07-20 09:42:15,217 main DEBUG Building Plugin[name=loggers, class=org.apache.logging.log4j.core.config.LoggersPlugin]. 
2016-07-20 09:42:15,217 main DEBUG createLoggers(={xyz.my.project, root}) 
2016-07-20 09:42:15,219 main DEBUG Configuration XmlConfiguration[location=C:\...\TheProject\target\classes\log4j2.xml] initialized 
2016-07-20 09:42:15,219 main DEBUG Starting configuration XmlConfiguration[location=C:\...\TheProject\target\classes\log4j2.xml] 
2016-07-20 09:42:15,219 main DEBUG Started configuration XmlConfiguration[location=C:\...\TheProject\target\classes\log4j2.xml] OK. 
2016-07-20 09:42:15,220 main TRACE Stopping [email protected]54... 
2016-07-20 09:42:15,220 main TRACE DefaultConfiguration notified 1 ReliabilityStrategies that config will be stopped. 
2016-07-20 09:42:15,221 main TRACE DefaultConfiguration stopping root LoggerConfig. 
2016-07-20 09:42:15,221 main TRACE DefaultConfiguration notifying ReliabilityStrategies that appenders will be stopped. 
2016-07-20 09:42:15,222 main TRACE DefaultConfiguration stopping remaining Appenders. 
2016-07-20 09:42:15,222 main DEBUG Shutting down OutputStreamManager SYSTEM_OUT.false-1 
2016-07-20 09:42:15,222 main TRACE DefaultConfiguration stopped 1 remaining Appenders. 
2016-07-20 09:42:15,222 main TRACE DefaultConfiguration cleaning Appenders from 1 LoggerConfigs. 
2016-07-20 09:42:15,222 main DEBUG Stopped [email protected]54 OK 
2016-07-20 09:42:15,295 main TRACE Reregistering MBeans after reconfigure. Selector=or[email protected]74e52ef6 
2016-07-20 09:42:15,295 main TRACE Reregistering context (1/1): 'c387f44' [email protected] 
2016-07-20 09:42:15,297 main TRACE Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=c387f44' 
2016-07-20 09:42:15,297 main TRACE Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=c387f44,component=StatusLogger' 
2016-07-20 09:42:15,298 main TRACE Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=c387f44,component=ContextSelector' 
2016-07-20 09:42:15,298 main TRACE Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=c387f44,component=Loggers,name=*' 
2016-07-20 09:42:15,298 main TRACE Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=c387f44,component=Appenders,name=*' 
2016-07-20 09:42:15,299 main TRACE Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=c387f44,component=AsyncAppenders,name=*' 
2016-07-20 09:42:15,299 main TRACE Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=c387f44,component=AsyncLoggerRingBuffer' 
2016-07-20 09:42:15,299 main TRACE Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=c387f44,component=Loggers,name=*,subtype=RingBuffer' 
2016-07-20 09:42:15,301 main DEBUG Registering MBean org.apache.logging.log4j2:type=c387f44 
2016-07-20 09:42:15,303 main DEBUG Registering MBean org.apache.logging.log4j2:type=c387f44,component=StatusLogger 
2016-07-20 09:42:15,305 main DEBUG Registering MBean org.apache.logging.log4j2:type=c387f44,component=ContextSelector 
2016-07-20 09:42:15,307 main DEBUG Registering MBean org.apache.logging.log4j2:type=c387f44,component=Loggers,name= 
2016-07-20 09:42:15,308 main DEBUG Registering MBean org.apache.logging.log4j2:type=c387f44,component=Loggers,name=xyz.my.myproject 
2016-07-20 09:42:15,309 main DEBUG Registering MBean org.apache.logging.log4j2:type=c387f44,component=Appenders,name=console 
2016-07-20 09:42:15,310 main DEBUG Registering MBean org.apache.logging.log4j2:type=c387f44,component=Appenders,name=file 
2016-07-20 09:42:15,310 main DEBUG Registering MBean org.apache.logging.log4j2:type=c387f44,component=Appenders,name=log-viewer 
2016-07-20 09:42:15,312 main TRACE Using default SystemClock for timestamps. 
2016-07-20 09:42:15,312 main TRACE Using DummyNanoClock for nanosecond timestamps. 
2016-07-20 09:42:15,312 main DEBUG Reconfiguration complete for context[name=c387f44] at URI C:\...\TheProject\target\classes\log4j2.xml ([email protected]) with optional ClassLoader: null 
2016-07-20 09:42:15,313 main DEBUG Shutdown hook enabled. Registering a new one. 
2016-07-20 09:42:15,314 main DEBUG LoggerContext[name=c387f44, [email protected]] started OK. 
2016-07-20 09:42:15.501 [main] [DEBUG] main.SQLHelperMain (SQLHelperMain.java:95) - Adding icon 
2016-07-20 09:42:16.168 [Thread-2] [INFO] main.SQLHelperMain (SQLHelperMain.java:390) - SQLHelperMain.parsingFinished(true) 
2016-07-20 09:42:16.424 [main] [DEBUG] main.SQLHelperMain (SQLHelperMain.java:82) - Open SQLHelperUI 
2016-07-20 09:42:17,652 main DEBUG Stopping LoggerContext[name=c387f44, [email protected]]... 
2016-07-20 09:42:17,653 main TRACE Unregistering 1 MBeans: [org.apache.logging.log4j2:type=c387f44] 
2016-07-20 09:42:17,654 main TRACE Unregistering 1 MBeans: [org.apache.logging.log4j2:type=c387f44,component=StatusLogger] 
2016-07-20 09:42:17,654 main TRACE Unregistering 1 MBeans: [org.apache.logging.log4j2:type=c387f44,component=ContextSelector] 
2016-07-20 09:42:17,654 main TRACE Unregistering 2 MBeans: [org.apache.logging.log4j2:type=c387f44,component=Loggers,name=xyz.my.project, org.apache.logging.log4j2:type=c387f44,component=Loggers,name=] 
2016-07-20 09:42:17,655 main TRACE Unregistering 3 MBeans: [org.apache.logging.log4j2:type=c387f44,component=Appenders,name=console, org.apache.logging.log4j2:type=c387f44,component=Appenders,name=file, org.apache.logging.log4j2:type=c387f44,component=Appenders,name=log-viewer] 
2016-07-20 09:42:17,655 main TRACE Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=c387f44,component=AsyncAppenders,name=*' 
2016-07-20 09:42:17,656 main TRACE Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=c387f44,component=AsyncLoggerRingBuffer' 
2016-07-20 09:42:17,657 main TRACE Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=c387f44,component=Loggers,name=*,subtype=RingBuffer' 
2016-07-20 09:42:17,657 main TRACE Stopping XmlConfiguration[location=C:\...\TheProject\target\classes\log4j2.xml]... 
2016-07-20 09:42:17,658 main TRACE XmlConfiguration notified 3 ReliabilityStrategies that config will be stopped. 
2016-07-20 09:42:17,658 main TRACE XmlConfiguration stopping 2 LoggerConfigs. 
2016-07-20 09:42:17,658 main TRACE XmlConfiguration stopping root LoggerConfig. 
2016-07-20 09:42:17,658 main TRACE XmlConfiguration notifying ReliabilityStrategies that appenders will be stopped. 
2016-07-20 09:42:17,658 main TRACE XmlConfiguration stopping remaining Appenders. 
2016-07-20 09:42:17,658 main DEBUG Shutting down FileManager logfile.log 
2016-07-20 09:42:17,659 main DEBUG Shutting down OutputStreamManager SYSTEM_OUT.false 
2016-07-20 09:42:17,659 main TRACE XmlConfiguration stopped 3 remaining Appenders. 
2016-07-20 09:42:17,659 main TRACE XmlConfiguration cleaning Appenders from 3 LoggerConfigs. 
2016-07-20 09:42:17,659 main DEBUG Stopped XmlConfiguration[location=C:\...\TheProject\target\classes\log4j2.xml] OK 
2016-07-20 09:42:17,660 main DEBUG Stopped LoggerContext[name=c387f44, [email protected]]... 
2016-07-20 09:42:27,713 AWT-EventQueue-0 DEBUG Not in a ServletContext environment, thus not loading WebLookup plugin. 
2016-07-20 09:42:27,713 AWT-EventQueue-0 DEBUG PluginManager 'Converter' found 41 plugins 
2016-07-20 09:42:27,715 AWT-EventQueue-0 DEBUG Jansi is not installed, cannot find org.fusesource.jansi.WindowsAnsiOutputStream 
2016-07-20 09:42:27,715 AWT-EventQueue-0 DEBUG Starting OutputStreamManager SYSTEM_OUT.false-3 
2016-07-20 09:42:27,716 AWT-EventQueue-0 DEBUG Starting LoggerContext[name=c387f44, [email protected]]... 
2016-07-20 09:42:27,716 AWT-EventQueue-0 DEBUG Reconfiguration started for context[name=c387f44] at URI null ([email protected]) with optional ClassLoader: null 
2016-07-20 09:42:27,716 AWT-EventQueue-0 DEBUG Using configurationFactory or[email protected]4d399216 
2016-07-20 09:42:27,716 AWT-EventQueue-0 TRACE Trying to find [log4j2-testc387f44.properties] using context class loader [email protected] 
2016-07-20 09:42:27,717 AWT-EventQueue-0 TRACE Trying to find [log4j2-testc387f44.properties] using [email protected] class loader. 
2016-07-20 09:42:27,717 AWT-EventQueue-0 TRACE Trying to find [log4j2-testc387f44.properties] using [email protected] class loader. 
2016-07-20 09:42:27,718 AWT-EventQueue-0 TRACE Trying to find [log4j2-testc387f44.properties] using ClassLoader.getSystemResource(). 
2016-07-20 09:42:27,718 AWT-EventQueue-0 TRACE Trying to find [log4j2-testc387f44.yml] using context class loader [email protected] 
2016-07-20 09:42:27,719 AWT-EventQueue-0 TRACE Trying to find [log4j2-testc387f44.yml] using [email protected] class loader. 
2016-07-20 09:42:27,720 AWT-EventQueue-0 TRACE Trying to find [log4j2-testc387f44.yml] using [email protected] class loader. 
2016-07-20 09:42:27,721 AWT-EventQueue-0 TRACE Trying to find [log4j2-testc387f44.yml] using ClassLoader.getSystemResource(). 
2016-07-20 09:42:27,721 AWT-EventQueue-0 TRACE Trying to find [log4j2-testc387f44.yaml] using context class loader [email protected] 
2016-07-20 09:42:27,722 AWT-EventQueue-0 TRACE Trying to find [log4j2-testc387f44.yaml] using [email protected] class loader. 
2016-07-20 09:42:27,722 AWT-EventQueue-0 TRACE Trying to find [log4j2-testc387f44.yaml] using [email protected] class loader. 
2016-07-20 09:42:27,723 AWT-EventQueue-0 TRACE Trying to find [log4j2-testc387f44.yaml] using ClassLoader.getSystemResource(). 
2016-07-20 09:42:27,723 AWT-EventQueue-0 TRACE Trying to find [log4j2-testc387f44.json] using context class loader [email protected] 
2016-07-20 09:42:27,724 AWT-EventQueue-0 TRACE Trying to find [log4j2-testc387f44.json] using [email protected] class loader. 
2016-07-20 09:42:27,724 AWT-EventQueue-0 TRACE Trying to find [log4j2-testc387f44.json] using [email protected] class loader. 
2016-07-20 09:42:27,724 AWT-EventQueue-0 TRACE Trying to find [log4j2-testc387f44.json] using ClassLoader.getSystemResource(). 
2016-07-20 09:42:27,725 AWT-EventQueue-0 TRACE Trying to find [log4j2-testc387f44.jsn] using context class loader [email protected] 
2016-07-20 09:42:27,725 AWT-EventQueue-0 TRACE Trying to find [log4j2-testc387f44.jsn] using [email protected] class loader. 
2016-07-20 09:42:27,726 AWT-EventQueue-0 TRACE Trying to find [log4j2-testc387f44.jsn] using [email protected] class loader. 
2016-07-20 09:42:27,726 AWT-EventQueue-0 TRACE Trying to find [log4j2-testc387f44.jsn] using ClassLoader.getSystemResource(). 
2016-07-20 09:42:27,727 AWT-EventQueue-0 TRACE Trying to find [log4j2-testc387f44.xml] using context class loader [email protected] 
2016-07-20 09:42:27,727 AWT-EventQueue-0 TRACE Trying to find [log4j2-testc387f44.xml] using [email protected] class loader. 
2016-07-20 09:42:27,728 AWT-EventQueue-0 TRACE Trying to find [log4j2-testc387f44.xml] using [email protected] class loader. 
2016-07-20 09:42:27,728 AWT-EventQueue-0 TRACE Trying to find [log4j2-testc387f44.xml] using ClassLoader.getSystemResource(). 
2016-07-20 09:42:27,728 AWT-EventQueue-0 TRACE Trying to find [log4j2-test.properties] using context class loader [email protected] 
2016-07-20 09:42:27,729 AWT-EventQueue-0 TRACE Trying to find [log4j2-test.properties] using [email protected] class loader. 
2016-07-20 09:42:27,729 AWT-EventQueue-0 TRACE Trying to find [log4j2-test.properties] using [email protected] class loader. 
2016-07-20 09:42:27,730 AWT-EventQueue-0 TRACE Trying to find [log4j2-test.properties] using ClassLoader.getSystemResource(). 
2016-07-20 09:42:27,730 AWT-EventQueue-0 TRACE Trying to find [log4j2-test.yml] using context class loader [email protected] 
2016-07-20 09:42:27,731 AWT-EventQueue-0 TRACE Trying to find [log4j2-test.yml] using [email protected] class loader. 
2016-07-20 09:42:27,731 AWT-EventQueue-0 TRACE Trying to find [log4j2-test.yml] using [email protected] class loader. 
2016-07-20 09:42:27,732 AWT-EventQueue-0 TRACE Trying to find [log4j2-test.yml] using ClassLoader.getSystemResource(). 
2016-07-20 09:42:27,732 AWT-EventQueue-0 TRACE Trying to find [log4j2-test.yaml] using context class loader [email protected] 
2016-07-20 09:42:27,732 AWT-EventQueue-0 TRACE Trying to find [log4j2-test.yaml] using [email protected] class loader. 
2016-07-20 09:42:27,733 AWT-EventQueue-0 TRACE Trying to find [log4j2-test.yaml] using [email protected] class loader. 
2016-07-20 09:42:27,733 AWT-EventQueue-0 TRACE Trying to find [log4j2-test.yaml] using ClassLoader.getSystemResource(). 
2016-07-20 09:42:27,734 AWT-EventQueue-0 TRACE Trying to find [log4j2-test.json] using context class loader [email protected] 
2016-07-20 09:42:27,734 AWT-EventQueue-0 TRACE Trying to find [log4j2-test.json] using [email protected] class loader. 
2016-07-20 09:42:27,735 AWT-EventQueue-0 TRACE Trying to find [log4j2-test.json] using [email protected] class loader. 
2016-07-20 09:42:27,735 AWT-EventQueue-0 TRACE Trying to find [log4j2-test.json] using ClassLoader.getSystemResource(). 
2016-07-20 09:42:27,735 AWT-EventQueue-0 TRACE Trying to find [log4j2-test.jsn] using context class loader [email protected] 
2016-07-20 09:42:27,736 AWT-EventQueue-0 TRACE Trying to find [log4j2-test.jsn] using [email protected]4 class loader. 
2016-07-20 09:42:27,736 AWT-EventQueue-0 TRACE Trying to find [log4j2-test.jsn] using [email protected] class loader. 
2016-07-20 09:42:27,737 AWT-EventQueue-0 TRACE Trying to find [log4j2-test.jsn] using ClassLoader.getSystemResource(). 
2016-07-20 09:42:27,737 AWT-EventQueue-0 TRACE Trying to find [log4j2-test.xml] using context class loader [email protected] 
2016-07-20 09:42:27,737 AWT-EventQueue-0 TRACE Trying to find [log4j2-test.xml] using [email protected] class loader. 
2016-07-20 09:42:27,738 AWT-EventQueue-0 TRACE Trying to find [log4j2-test.xml] using [email protected] class loader. 
2016-07-20 09:42:27,738 AWT-EventQueue-0 TRACE Trying to find [log4j2-test.xml] using ClassLoader.getSystemResource(). 
2016-07-20 09:42:27,738 AWT-EventQueue-0 TRACE Trying to find [log4j2c387f44.properties] using context class loader [email protected] 
2016-07-20 09:42:27,739 AWT-EventQueue-0 TRACE Trying to find [log4j2c387f44.properties] using [email protected] class loader. 
2016-07-20 09:42:27,739 AWT-EventQueue-0 TRACE Trying to find [log4j2c387f44.properties] using [email protected] class loader. 
2016-07-20 09:42:27,740 AWT-EventQueue-0 TRACE Trying to find [log4j2c387f44.properties] using ClassLoader.getSystemResource(). 
2016-07-20 09:42:27,740 AWT-EventQueue-0 TRACE Trying to find [log4j2c387f44.yml] using context class loader [email protected] 
2016-07-20 09:42:27,740 AWT-EventQueue-0 TRACE Trying to find [log4j2c387f44.yml] using [email protected] class loader. 
2016-07-20 09:42:27,741 AWT-EventQueue-0 TRACE Trying to find [log4j2c387f44.yml] using [email protected] class loader. 
2016-07-20 09:42:27,741 AWT-EventQueue-0 TRACE Trying to find [log4j2c387f44.yml] using ClassLoader.getSystemResource(). 
2016-07-20 09:42:27,742 AWT-EventQueue-0 TRACE Trying to find [log4j2c387f44.yaml] using context class loader [email protected] 
2016-07-20 09:42:27,742 AWT-EventQueue-0 TRACE Trying to find [log4j2c387f44.yaml] using [email protected] class loader. 
2016-07-20 09:42:27,742 AWT-EventQueue-0 TRACE Trying to find [log4j2c387f44.yaml] using [email protected] class loader. 
2016-07-20 09:42:27,743 AWT-EventQueue-0 TRACE Trying to find [log4j2c387f44.yaml] using ClassLoader.getSystemResource(). 
2016-07-20 09:42:27,743 AWT-EventQueue-0 TRACE Trying to find [log4j2c387f44.json] using context class loader [email protected] 
2016-07-20 09:42:27,744 AWT-EventQueue-0 TRACE Trying to find [log4j2c387f44.json] using [email protected] class loader. 
2016-07-20 09:42:27,744 AWT-EventQueue-0 TRACE Trying to find [log4j2c387f44.json] using [email protected] class loader. 
2016-07-20 09:42:27,744 AWT-EventQueue-0 TRACE Trying to find [log4j2c387f44.json] using ClassLoader.getSystemResource(). 
2016-07-20 09:42:27,745 AWT-EventQueue-0 TRACE Trying to find [log4j2c387f44.jsn] using context class loader [email protected] 
2016-07-20 09:42:27,745 AWT-EventQueue-0 TRACE Trying to find [log4j2c387f44.jsn] using [email protected] class loader. 
2016-07-20 09:42:27,746 AWT-EventQueue-0 TRACE Trying to find [log4j2c387f44.jsn] using [email protected] class loader. 
2016-07-20 09:42:27,746 AWT-EventQueue-0 TRACE Trying to find [log4j2c387f44.jsn] using ClassLoader.getSystemResource(). 
2016-07-20 09:42:27,746 AWT-EventQueue-0 TRACE Trying to find [log4j2c387f44.xml] using context class loader [email protected] 
2016-07-20 09:42:27,747 AWT-EventQueue-0 TRACE Trying to find [log4j2c387f44.xml] using [email protected] class loader. 
2016-07-20 09:42:27,747 AWT-EventQueue-0 TRACE Trying to find [log4j2c387f44.xml] using [email protected]c387f44 class loader. 
2016-07-20 09:42:27,747 AWT-EventQueue-0 TRACE Trying to find [log4j2c387f44.xml] using ClassLoader.getSystemResource(). 
2016-07-20 09:42:27,748 AWT-EventQueue-0 TRACE Trying to find [log4j2.properties] using context class loader [email protected] 
2016-07-20 09:42:27,748 AWT-EventQueue-0 TRACE Trying to find [log4j2.properties] using [email protected] class loader. 
2016-07-20 09:42:27,748 AWT-EventQueue-0 TRACE Trying to find [log4j2.properties] using [email protected] class loader. 
2016-07-20 09:42:27,749 AWT-EventQueue-0 TRACE Trying to find [log4j2.properties] using ClassLoader.getSystemResource(). 
2016-07-20 09:42:27,749 AWT-EventQueue-0 TRACE Trying to find [log4j2.yml] using context class loader [email protected] 
2016-07-20 09:42:27,750 AWT-EventQueue-0 TRACE Trying to find [log4j2.yml] using [email protected] class loader. 
2016-07-20 09:42:27,750 AWT-EventQueue-0 TRACE Trying to find [log4j2.yml] using [email protected] class loader. 
2016-07-20 09:42:27,750 AWT-EventQueue-0 TRACE Trying to find [log4j2.yml] using ClassLoader.getSystemResource(). 
2016-07-20 09:42:27,751 AWT-EventQueue-0 TRACE Trying to find [log4j2.yaml] using context class loader [email protected] 
2016-07-20 09:42:27,751 AWT-EventQueue-0 TRACE Trying to find [log4j2.yaml] using [email protected] class loader. 
2016-07-20 09:42:27,751 AWT-EventQueue-0 TRACE Trying to find [log4j2.yaml] using [email protected] class loader. 
2016-07-20 09:42:27,752 AWT-EventQueue-0 TRACE Trying to find [log4j2.yaml] using ClassLoader.getSystemResource(). 
2016-07-20 09:42:27,752 AWT-EventQueue-0 TRACE Trying to find [log4j2.json] using context class loader [email protected] 
2016-07-20 09:42:27,753 AWT-EventQueue-0 TRACE Trying to find [log4j2.json] using [email protected] class loader. 
2016-07-20 09:42:27,753 AWT-EventQueue-0 TRACE Trying to find [log4j2.json] using [email protected] class loader. 
2016-07-20 09:42:27,753 AWT-EventQueue-0 TRACE Trying to find [log4j2.json] using ClassLoader.getSystemResource(). 
2016-07-20 09:42:27,754 AWT-EventQueue-0 TRACE Trying to find [log4j2.jsn] using context class loader [email protected] 
2016-07-20 09:42:27,754 AWT-EventQueue-0 TRACE Trying to find [log4j2.jsn] using [email protected] class loader. 

请让我知道,如果你想进一步的细节。

+0

您的log4j配置可能会有所帮助:) – Berger

+0

@Berger:这是一个简单的简单配置。尽管如此,我会添加它。 – Markus

+0

您可以发布一个示例线程,以及如何创建LOG? – Berger

回答

0

我傻:

起初,我写了一个Swing应用程序通过appl.setVisible(true);主线程打开UI。最后我还加入了LogManager.shutdown();来清理一旦终止的资源。

在浏览互联网并通过SO获取有关Swing的更多信息时,代码出现在适当的多线程应用程序中(请参阅SwingUtilities.invokeLater(new Runnable() {...});),同时保持LogManager的关闭挂接。

修复

由于@rgoers的优秀很好的答案,我看到从xyz.my.logger改变记录器的名称:DEBUGxyz.my.logger:OFF

+1

请记住,Log4j 2将在JVM关闭钩子中自动执行任何必要的清理,因此不需要显式调用LogManager.shutdown()。 –

0

我确定希望看到您的应用程序。从日志看起来应用程序已经结束。 AWT-EventQueue-0(一个新的线程?)然后开始运行。日志已关闭,因此它会尝试重新初始化,但不知道要使用哪种配置。为了解决这个问题,你的应用程序创建的线程需要在主线程结束之前运行。

+0

这听起来像是一个非常有前途的输入。我想到的是:如果我使用'SwingUtilities.invokeLater(new Runnable(){...});',我怎样才能编写一个Swing应用程序?而且,在200+行中,它再次打印配置文件的正确位置。 – Markus