I think I've sussed out the problem. It was a catch 22 between JNDI and log4j. The 
jboss implementation of JNDI was wanting to write 'trace' level messages to the 
rootLogger (which was set to the output level ALL) to which was attached the 
JMSAppender. The problem was that the JMSAppender was not fully configured (hence the 
JNDI calls) and this was causing the problems.
 
The solution I've implemented is to create my own logger to which is attached the 
JMSAppender and to also ensure the this Loggers level was set higher than 'trace'.
 
Martin
 

        -----Original Message----- 
        From: [EMAIL PROTECTED] 
        Sent: Wed 23/07/2003 11:34 
        To: Log4J Users List 
        Cc: 
        Subject: RE: Newbie JMSAppender Problems
        
        

        I started using log4j 1.2.8 but was informed that I would not be able
        to upgrade log4j on the target release machine. Here is the stack
        trace, output and a snippet of the code where the error occurs.
        
        Here is the code snippet.......................
        
        private InitialContext ctx = null;
        public static void main(String args[]) {
          System.out.println("Started Client (stdout)");
          TestClient tc = new TestClient();
          tc.testJMS();
          tc.testLogging();
          System.out.println("Finished Client (stdout)");
        }
        
        private void createInitialContext() {
          if (ctx == null) {
            System.out.println("Creating InitialContext");
            try {
              ctx = new InitialContext();
              Hashtable ht = ctx.getEnvironment();
              System.out.println(ht);
            } catch (NamingException e) {
              e.printStackTrace();
            }
            System.out.println("Created InitialContext");
          }
        }
        public void testJMS() {
          TopicConnection conn;
          try {
          createInitialContext();
          Object tmp = ctx.lookup("TopicConnectionFactory");
          TopicConnectionFactory qcf = (TopicConnectionFactory) tmp;
          conn = qcf.createTopicConnection();
          .......
          .......
        
        public void testLogging() {
          createInitialContext();
          Category log = null;
          log = Category.getRoot();
          log.error("First JMS Message (to ERROR)");
        }
        
        As you can see the testJMS method is called before any of the logging is
        setup. When I do the first lookup (in the testJMS method) All the log4j
        stuff is loaded and configured using the log4j.properties file and it is
        here that the NamingException is thrown.
        
        The output & stack trace from this code is as follows....
        
        Started Client (stdout)
        Creating InitialContext
        {
        java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory,
        java.naming.provider.url=onion:1099,
        java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
        }
        Created InitialContext
        log4j: Parsing for [root] with value=[ALL, jms].
        log4j: Priority token is [ALL].
        log4j: Category root set to DEBUG
        log4j: Parsing appender named "jms".
        log4j: Setting property [topicConnectionFactoryBindingName] to 
[TopicConnectionFactory].
        log4j: Setting property [topicBindingName] to [topic/testTopic].
        log4j: Setting property [threshold] to [ERROR].
        log4j:ERROR Error while activating options for appender named [jms].
        javax.naming.NamingException: Could not dereference object.  Root exception is 
java.lang.NullPointerException
         at 
org.jboss.mq.referenceable.SpyConnectionFactoryObjectFactory.getObjectInstance(SpyConnectionFactoryObjectFactory.java:40)
         at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:301)
         at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:437)
         at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:333)
         at javax.naming.InitialContext.lookup(InitialContext.java:347)
         at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:421)
         at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:333)
         at javax.naming.InitialContext.lookup(InitialContext.java:347)
         at org.apache.log4j.net.JMSAppender.lookup(JMSAppender.java:181)
         at org.apache.log4j.net.JMSAppender.activateOptions(JMSAppender.java:161)
         at org.apache.log4j.config.PropertySetter.activate(PropertySetter.java:247)
         at 
org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:123)
         at 
org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:87)
         at 
org.apache.log4j.PropertyConfigurator.parseAppender(PropertyConfigurator.java:637)
         at 
org.apache.log4j.PropertyConfigurator.parseCategory(PropertyConfigurator.java:595)
         at 
org.apache.log4j.PropertyConfigurator.configureRootCategory(PropertyConfigurator.java:502)
         at 
org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:410)
         at 
org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:436)
         at 
org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:455)
         at org.apache.log4j.Category.<clinit>(Category.java:146)
         at org.jboss.logging.Logger.<init>(Logger.java:55)
         at org.jboss.logging.Logger.getLogger(Logger.java:45)
         at 
org.jboss.mq.referenceable.SpyConnectionFactoryObjectFactory.<clinit>(SpyConnectionFactoryObjectFactory.java:25)
         at java.lang.Class.forName0(Native Method)
         at java.lang.Class.forName(Class.java:217)
         at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:42)
         at 
javax.naming.spi.NamingManager.getObjectFactoryFromReference(NamingManager.java:129)
         at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:299)
         at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:437)
         at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:333)
         at javax.naming.InitialContext.lookup(InitialContext.java:347)
         at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:421)
         at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:333)
         at javax.naming.InitialContext.lookup(InitialContext.java:347)
         at com.pindartech.cm.error.TestClient.testJMS(TestClient.java:50)
         at com.pindartech.cm.error.TestClient.main(TestClient.java:16)
        log4j: Parsed "jms" options.
        log4j: Finished configuring.
        Finished Client (stdout)
        
        
                -----Original Message-----
                From: Ceki Gülcü [mailto:[EMAIL PROTECTED]
                Sent: Wed 23/07/2003 09:59
                To: Log4J Users List
                Cc:
                Subject: Re: Newbie JMSAppender Problems
               
               
        
        
                The actual stack trace of the exception would have been useful.
               
                Is the jndi.properties file found?
               
                You might want to try log4j 1.2.8 where you can specify the properties 
that
                are in jndi.properties within the log4j config file.
               
                At 09:14 AM 7/23/2003 +0100, [EMAIL PROTECTED] wrote:
                >Hi,
                >I'm having problems using the JMSAppender. I'm using JBoss 2.4.4 and 
Log4J
                >1.1.2 .  What happens is I get a NamaingException when configuring the
                >JMSAppender.
                >
                >My log4j.properties files looks like this.......
                >
                >log4j.debug=true
                >log4j.rootCategory=ALL, jms
                >#now lets go for the JMS log
                >log4j.appender.jms=org.apache.log4j.net.JMSAppender
                >log4j.appender.jms.threshold=ERROR
                >log4j.appender.jms.layout=org.apache.log4j.SimpleLayout
                >log4j.appender.jms.TopicBindingName=topic/testTopic
                >log4j.appender.jms.TopicConnectionFactoryBindingName=ConnectionFactory
               
                [snip]
               
                >
                >Martin
               
               
               
                --
                Ceki  For log4j documentation consider "The complete log4j manual"
                       ISBN: 2970036908  http://www.qos.ch/shop/products/clm_t.jsp
               
               
                ---------------------------------------------------------------------
                To unsubscribe, e-mail: [EMAIL PROTECTED]
                For additional commands, e-mail: [EMAIL PROTECTED]
               
               
        
        

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to