In Log4J, why %C in ConversionPattern prints '?' (question mark) with AsyncAppender? -


i have trouble when using %c in conversionpattern asyncappender.

my lo4j configuration is:

<?xml version="1.0" encoding="utf-8"?> <!doctype log4j:configuration system "log4j.dtd">  <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">     <appender name="console" class="org.apache.log4j.consoleappender">         <layout class="org.apache.log4j.patternlayout">             <param name="conversionpattern" value="%d{yyyy/mm/dd hh:mm:ss,sss} %c{1} - %m%n" />         </layout>     </appender>     <appender name="async_console" class="org.apache.log4j.asyncappender">         <param name="buffersize" value="1000" />         <appender-ref ref="console" />     </appender>     <root>         <level value="debug" />         <!--         <appender-ref ref="console" />         -->         <appender-ref ref="async_console" />     </root> </log4j:configuration> 

and test code is:

@test public void testasync() {     domconfigurator             .configure("src/test/resources/learningtest/log4j/log4j_test_async.xml");     logger log = logger.getlogger(getclass());     log.debug("hello, world!");     try {         thread.sleep(1000);     } catch (interruptedexception e) {         e.printstacktrace();     } } 

the result of test code is:

2012/03/15 11:51:22,570 ? - hello, world!

without asynappender, works fine:

2012/03/15 11:51:06,002 log4jtest - hello, world!

with %c (category), works fine, too.

what missing?

please let me know.

thanks in advance :-)

reference:

http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/patternlayout.html

when using "%c" or "%m", log4j uses throwable.getstacktrace stacktrace , use information caller class , method. problem when using asyncappender, throwable created in thread , stacktrace not contain caller method.


Comments