When logging an exception, LOG4J 1.0.2 runs into a NullPointerExcepion under the following circumstances (stack trace and properties file is below): I have two categories: gl.exception gl.exception.stack I defined a static category in the Exception Class: private static final Category LOG = Category.getInstance("gl.exception"); In the constructor of the Exception I log the exceptionusng the following code: LOG.error(this.getLocalizedMessage(), this); Now LOG4J get'S a NullPointerException in the method Category.forcedLog(String, Priority, Object, Throwable) This is because myCategory is null. This happens only if I have defined both of the categories in the configuration file. if there is on gl.exception in it, there is no error. I assume it has something to do with the new "hierarchie management" in the category classes that was mentioned. Here is the configuration file: log4j.rootCategory=DEBUG, stdout log4j.category.gl.servlet=DEBUG log4j.category.gl.dispatcher=DEBUG log4j.category.gl.ucc=DEBUG log4j.category.gl.ejb=DEBUG log4j.category.gl.communication=DEBUG log4j.category.gl.businesscommand=DEBUG log4j.category.gl.xml=DEBUG log4j.category.gl.bucket=DEBUG log4j.category.gl.gui=DEBUG log4j.category.gl.exception=ERROR log4j.category.gl.exception.stack=ERROR log4j.appender.stdout=org.apache.log4j.FileAppender log4j.appender.stdout.File=System.out log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d{ISO8601} [%t] %-5p %c %x - %m%n log4j.appender.file=org.log4j.RollingFileAppender log4j.appender.file.File=rolling.log log4j.appender.file.MaxFileSize=100KB log4j.appender.file.MaxBackupIndex=2 log4j.appender.file.layout=org.apache.log4j.PatternLayout log4j.appender.file.layout.ConversionPattern=%d{ISO8601} %p %t %c - %m%n Debugger Stack Trace Report: Thread[main,5,main] (Alive) Uncaught exception (java.lang.NullPointerException) Category.forcedLog(String, Priority, Object, Throwable) this=(org.apache.log4j.Category) org.apache.log4j.Category@2f65 fqn=(java.lang.String) org.apache.log4j.Category priority=(org.apache.log4j.Priority) ERROR message=(java.lang.Object) null t=(java.lang.Throwable) test.org.germanlloyd.tec.log.TestException s=(java.lang.String) null Category.error(Object, Throwable) this=(org.apache.log4j.Category) org.apache.log4j.Category@2f65 message=(java.lang.Object) null t=(java.lang.Throwable) test.org.germanlloyd.tec.log.TestException TestException() this=(test.org.germanlloyd.tec.log.TestException) test.org.germanlloyd.tec.log.TestException TestLog.main(String []) args=([Ljava.lang.String;) [Ljava.lang.String;@4e1c
Wolfram, I have tried the config file you supplied with the program supplied below. It worked just fine. Can you maybe try it? Ceki import org.apache.log4j.PropertyConfigurator; import org.apache.log4j.Category; public class x { private static final Category LOG = Category.getInstance("gl.exception"); public static void main(String argv[]) { PropertyConfigurator.configure(argv[0]); LOG.error("Hello"); } }
OK. I can reliably reproduce the bug as follows: File x.java ------------------------------------------------- import org.apache.log4j.PropertyConfigurator; import org.apache.log4j.Category; public class x { public static void main(String argv[]) { PropertyConfigurator.configure(argv[0]); Category LOG = Category.getInstance("gl.exception"); LOG.error(new Integer(0)); } } ------------------------------------------------------------- File x.lcf -------------------------------------------------- log4j.rootCategory=DEBUG, stdout log4j.category.gl.exception.stack=ERROR log4j.appender.stdout=org.apache.log4j.FileAppender log4j.appender.stdout.File=System.out log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d{ISO8601} [%t] %-5p %c %x - %m% n -------------------------------------------------------------------------- This will systematically result in: UpdateParents called for gl.exception.stack Updating parent : gl.exception No parent gl.exception found. Creating ProvisionNode. Updating parent : gl No parent gl found. Creating ProvisionNode. UpdateParents called for gl.exception Updating parent : gl Exception in thread "main" java.lang.NullPointerException at org.apache.log4j.Category.forcedLog(Category.java:452) at org.apache.log4j.Category.error(Category.java:367) at x.main(x.java:12) I know what the problem is and the fix is on the way! Ceki