You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Micah Whitacre <mk...@gmail.com> on 2009/01/17 00:07:18 UTC

NPE when checking if Debug is enabled

Hey All,
 I'm currently using version 1.2.14 of log4j on Ubuntu.  I have a
weird situation where occasionally a NullPointerException[1] is being
thrown by when I'm trying to check the logger to see if debug is
enabled.  Even though the stack trace contains the Category class, I
am coding against the Logger class and the method call is actually
logger.isDebugEnabled().  The configuration for the log4j.properties
files is included[2] below as well.  As you can see I only configure a
root logger so all loggers should have a parent and its level should
be set.  I do not programmatically alter the level or parent of the
logger anywhere else in the code.  So looking through the Category
class my assumption is that somehow line 443 is being hit therefore
returning null as the effective level.  But that doesn't really make
sense, if the root logger has a level set at "info".
 Has anyone seen or experienced this exception randomly occurring?  I
have multiple calls to check to see if debug is enabled so some checks
are succeeding but an occasional one pops up that throwing the
exception.  The JVM it is running it currently catches the exception
and retries the operation and eventually it goes away, however I'd
like to stop that JVM from thrashing by eliminating this exception
being thrown.

Thanks in advance for your help,
Micah

[1] - java.lang.NullPointerException
       at org.apache.log4j.Priority.isGreaterOrEqual(Priority.java:122)
       at org.apache.log4j.Category.isDebugEnabled(Category.java:733)

[2] -
log4j.rootLogger = info, console
log4j.appender.console = org.apache.log4j.ConsoleAppender
log4j.appender.console.layout = org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern = %-4r [%t] %-5p %c %x - %m%nmw0

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