3 Replies Latest reply on Aug 19, 2002 1:48 AM by Burkhard Eggers

    log4j JMSAppender

    Burkhard Eggers Newbie

      Hi,
      I need to configure a JMS-Appender in the log4j-module of JBoss 3.0.
      Well, the time log4j-service is coming up, the JNDI is not even started (I guess so looking at the JBoss-log).
      That seems ok because everything should be logged.
      But when I want to use a JMSAppender, JNDI must be there when log4j comes up.

      So, is it impossible to use the JBoss-MQ as log4j-JMS-destination and hence is it necessary to run another JMS server outside JBoss to get a JMSAppender running?
      I guess not, since you got a outcommented JMSAppender in the standard-log4j.xml.

      So where am I wrong?

        • 1. Re: log4j JMSAppender
          Peter Antman Expert

          Hi, as far as I know you are not wrong. When log4j is configured there is no JMS support in the running server, so you cant log to JMS then.

          One solution (which I use) is to write an MBean and let it be started after JMS has come up which programatically ads the JMS appender.

          Here are the code in the startService I use (with a custom appander, if you use the log4j one you should probably also set a layout):

          public void startService() throws Exception
          {
          Category root = Category.getRoot();
          Enumeration apps = root.getAllAppenders();

          // We need to do it this way, otherwise we end up in a loop.
          // All logging in org.jboss.mq is delegated to this category,
          // and all appenders from the root hierachy is added to it.
          // But logging calles here are not allowed to go higher
          // than this, because we will then get a loop.
          mq = Category.getInstance("org.jboss.mq");
          mq.setAdditivity(false);
          while(apps.hasMoreElements()) {
          mq.addAppender((Appender)apps.nextElement());
          }

          // Threashold not used yet
          appender = new JmsLogger();
          appender.setTopicConnectionFactoryBindingName(topicConnectionFactoryBindingName);
          appender.setTopicBindingName( topicBindingName );
          appender.setName("JMS");
          appender.activateOptions();
          Category.getRoot().addAppender(appender);


          // Change the stdout/stderr mappings, we do not like debugging to
          // sterr ass ERR priority!
          out = System.out;
          err = System.err;

          Category category = Category.getInstance("Default");
          System.setOut(new CategoryStream(category, Priority.DEBUG, out));
          System.setErr(new CategoryStream(category, Priority.WARN, err));
          }

          //Peter

          • 2. Re: log4j JMSAppender
            Peter Antman Expert

            Hm, my comment disapeared.

            As far as I know it is not possible to use the example, since no JMS stuff is up and running when log4j is initialized. One way to solve it is to programatically set the JMS appender up in an MBean AFTER the JMS system ha come up.

            I have done that (but with a custom appander, with the log4j one you probably have to set the Layout to). Here's the start method:

            /**
            * Set up the JMS logger.
            */
            public void startService() throws Exception
            {
            Category root = Category.getRoot();
            Enumeration apps = root.getAllAppenders();

            // We need to do it this way, otherwise we end up in a loop.
            // All logging in org.jboss.mq is delegated to this category,
            // and all appenders from the root hierachy is added to it.
            // But logging calles here are not allowed to go higher
            // than this, because we will then get a loop.
            mq = Category.getInstance("org.jboss.mq");
            mq.setAdditivity(false);
            while(apps.hasMoreElements()) {
            mq.addAppender((Appender)apps.nextElement());
            }

            // Threashold not used yet
            appender = new JmsLogger();
            appender.setTopicConnectionFactoryBindingName(topicConnectionFactoryBindingName);
            appender.setTopicBindingName( topicBindingName );
            appender.setName("JMS");
            appender.activateOptions();
            Category.getRoot().addAppender(appender);


            // Change the stdout/stderr mappings, we do not like debugging to
            // sterr ass ERR priority!
            out = System.out;
            err = System.err;

            Category category = Category.getInstance("Default");
            System.setOut(new CategoryStream(category, Priority.DEBUG, out));
            System.setErr(new CategoryStream(category, Priority.WARN, err));
            }

            //Peter

            • 3. Re: log4j JMSAppender
              Burkhard Eggers Newbie

              thank you peter,
              I have been absent two weeks, so I didn't reply inmediately.