logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ralph Goers (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (LOG4J2-462) LevelPatternConverter.format may throw NPE
Date Fri, 03 Jan 2014 16:45:57 GMT

    [ https://issues.apache.org/jira/browse/LOG4J2-462?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13861652#comment-13861652
] 

Ralph Goers commented on LOG4J2-462:
------------------------------------

Yes, that make sense to me as well.

> LevelPatternConverter.format may throw NPE
> ------------------------------------------
>
>                 Key: LOG4J2-462
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-462
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 2.0-beta9
>         Environment: java version "1.6.0_65"
> Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
> Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)
>            Reporter: Daisuke Baba
>
> I found an issue when enabling asynchronous appenders with `-DLog4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector`
and I also got a workaround to fix it.
> Note that I invoke LogContext.setConfigLocation() then LogContext.reconfigure() in order
to apply log4j2.xml programatically.
> 1. Stacktrace ... See the bottom of the Description as it is a large portion.
> 2. Workaround
>      Just to get rid of toString() at line 123 from the following snippet:
> {code:title=2.0-beta-9.org.apache.logging.log4j.core.pattern.LevelPatternConverter.java|borderStyle=solid}
> 122 public void format(final LogEvent event, final StringBuilder output) {
> 123     output.append(levelMap == null ? event.getLevel().toString() : levelMap.get(event.getLevel()));
> 124 }
> {code}
> The workaround is as follows:
> {code:title=MyWorkaround|borderStyle=solid}
> 122 public void format(final LogEvent event, final StringBuilder output) {
> 123     output.append(levelMap == null ? event.getLevel() : levelMap.get(event.getLevel()));
> 124 }
> {code}
> 3. Log4j2.xml
> {code:title=log4j2.xml snip|borderStyle=solid}
> 		<RollingRandomAccessFile name="MySizeRollingLog"
> 			fileName="foo.log"
> 			filePattern="foo-%d{MM-dd-yyyy}-%i.log.gz">
> 			<PatternLayout
> 				pattern="%d{yyyy-MM-dd HH:mm:ss,SSS z} %-5p [%t] (%F:%L) - [server($${sys:something})]-[%X{Something}]-%m%n"
/>
> 			<Policies>
> 				<TimeBasedTriggeringPolicy interval="1"
> 					modulate="true" />
> 				<SizeBasedTriggeringPolicy size="1000KB" />
> 			</Policies>
> 			<DefaultRolloverStrategy max="3" />
> 		</RollingRandomAccessFile>
> {code}
> I'm not sure why event.getLevel() was null but the workaround works for me.
> ----
> Full stacktrace:
> 2013-12-05 09:36:58,947 ERROR An exception occurred processing Appender MySizeRollingLog
java.lang.NullPointerException
> at org.apache.logging.log4j.core.pattern.LevelPatternConverter.format(LevelPatternConverter.java:122)
> at org.apache.logging.log4j.core.pattern.PatternFormatter.format(PatternFormatter.java:36)
> at org.apache.logging.log4j.core.layout.PatternLayout.toSerializable(PatternLayout.java:167)
> at org.apache.logging.log4j.core.layout.PatternLayout.toSerializable(PatternLayout.java:52)
> at org.apache.logging.log4j.core.layout.AbstractStringLayout.toByteArray(AbstractStringLayout.java:45)
>  at org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender.append(AbstractOutputStreamAppender.java:111)
> at org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender.append(RollingRandomAccessFileAppender.java:96)
> at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:99)
> at org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:425)
> at org.apache.logging.log4j.core.async.AsyncLoggerConfig.asyncCallAppenders(AsyncLoggerConfig.java:116)
> at org.apache.logging.log4j.core.async.AsyncLoggerConfigHelper$Log4jEventWrapperHandler.onEvent(AsyncLoggerConfigHelper.java:218)
> at org.apache.logging.log4j.core.async.AsyncLoggerConfigHelper$Log4jEventWrapperHandler.onEvent(AsyncLoggerConfigHelper.java:203)
> at com.lmax.disruptor.BatchEventProcessor.run(BatchEventProcessor.java:133)
> at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
> at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
>  at java.lang.Thread.run(Thread.java:695)



--
This message was sent by Atlassian JIRA
(v6.1.5#6160)

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Mime
View raw message