1 2 Previous Next 20 Replies Latest reply on Dec 19, 2011 3:34 PM by suikast42

    Custom logger on AS 6

    nickarls

      Hi,

       

        I've played around with a custom log4j-logger but so far, no go. What I've done:

       

      I've packed my logger in a jar in <JBOSS_HOME>/server/default/lib, the logger looks something like

       

      public class DummyLogger extends AppenderSkeleton

      {

       

                @Override

                public void close()

                {

                }

       

       

                @Override

                public boolean requiresLayout()

                {

                          return true;

                }

       

       

                @Override

                protected void append(LoggingEvent event)

                {

                          System.out.println("Logging " + event.getMessage() );

                }

       

      }

       

      and included in jboss-logging.xml like

       

      <log4j-appender name="DUMMY" class="concept.DummyLogger">

                          <error-manager>

                                    <only-once/>

                          </error-manager>

       

                          <level name="DEBUG"/>

       

                          <formatter>

                                    <pattern-formatter pattern="%d %-5p [%c] (%t) %m%n"/>

                          </formatter>

      </log4j-appender>

       

      and

       

         <root-logger>

            <level name="${jboss.server.log.threshold:DEBUG}"/>

            <handlers>

               <handler-ref name="CONSOLE"/>

               <handler-ref name="FILE"/>

               <handler-ref name="DUMMY"/>

            </handlers>

         </root-logger>

       

      Am I missing something trivial?

        • 1. Custom logger on AS 6
          nickarls

          If I make a typo in the class name the AS reacts so I guess the class is picked up. It's not just getting any action. And the documentation on loggers on AS 6 was a bit...thin that last time I checked...

          • 2. Re: Custom logger on AS 6
            jaikiran

            Just to check whether it's the logging level which is preventing the call to your append method, try adding this method to that appender:

            @Override
            public void doAppend(LoggingEvent event) {
            
              System.out.println("Custom appender invoked");
              super.doAppend(event);
            }  
            
            • 3. Re: Custom logger on AS 6
              nickarls

              I don't get any output, I've tried fiddling with most thresholds I could find...

              • 4. Re: Custom logger on AS 6
                nickarls

                Does anyone have an example of a custom logger + jboss-logging.xml that shows how the log levels are set up (and info on if you use jboss logging, slf4j or what for application logging)?

                • 5. Re: Custom logger on AS 6
                  nickarls

                  I tried uncommenting the SMTP logger, add the handler ref to the root logger and set it's threshold to INFO for a boot. I didn't get any warnings about wrong mail server etc (kept the default values).

                  • 6. Re: Custom logger on AS 6
                    nickarls

                    log4j appender? working? anyone?

                    • 7. Re: Custom logger on AS 6
                      jaikiran

                      Let me give it a try this week, if no else gets there by then. If you have something ready that I can easily test/reuse, please attach it here.

                      • 8. Re: Custom logger on AS 6
                        nickarls

                        I have a dummy logger (attached) that basically just does

                         

                        public class DummyLogger extends AppenderSkeleton

                        {

                         

                         

                           public void close()

                           {

                           }

                         

                         

                           public boolean requiresLayout()

                           {

                              return true;

                           }

                         

                         

                           @Override

                           protected void append(LoggingEvent event)

                           {

                              System.out.println("Custom appender invoked");

                              super.doAppend(event);

                           }

                         

                         

                        }

                         

                        I add it to the root logger (copied from SMTP definition) and logging shows up for console and file but nothing from here. FQCN is jboss.logtest.DummyLogger

                        • 9. Re: Custom logger on AS 6
                          jaikiran

                          There is more than one issue in here.

                           

                          1) jboss-logmanager doesn't report a error which makes it look like the appender is just not picked up. org.jboss.logmanager.LoggerNode has this:

                           

                          void publish(final ExtLogRecord record) {
                                  for (Handler handler : handlers) try {
                                      handler.publish(record);
                                  } catch (VirtualMachineError e) {
                                      throw e;
                                  } catch (Throwable t) {
                                      // todo - error handler
                                  }
                                  if (useParentHandlers) {
                                      final LoggerNode parent = this.parent;
                                      if (parent != null) parent.publish(record);
                                  }
                              }
                          

                           

                          Notice the Throwable catch block. That's where it's ending up currently.

                           

                          2) The real issue is that the jboss-logmanager-log4j project is incompatible with the version of log4j (1.2.14) that's shipped in JBoss AS. The jboss-logmanager-log4j requires 1.2.15 http://anonsvn.jboss.org/repos/common/jboss-logmanager-log4j/trunk/pom.xml and runs into a:

                           

                          16:17:24,763 ERROR [STDERR] java.lang.NoSuchMethodError: org.apache.log4j.spi.LoggingEvent.<init>(Ljava/lang/String;Lorg/apache/log4j/Category;JLorg/apache/log4j/Level;Ljava/lang/Object;Ljava/lang/String;Lorg/apache/log4j/spi/ThrowableInformation;Ljava/lang/String;Lorg/apache/log4j/spi/LocationInfo;Ljava/util/Map;)V
                          

                           

                          in the org.jboss.logmanager.log4j.ConvertedLoggingEvent constructor:

                           

                          public final class ConvertedLoggingEvent extends LoggingEvent {
                          ...
                          public ConvertedLoggingEvent(final ExtLogRecord rec) {
                                  super(rec.getLoggerClassName(),
                                          new DummyCategory(rec.getLoggerName()),
                                          rec.getMillis(),
                                          LevelMapping.getPriorityFor(rec.getLevel()),
                                          rec.getMessage(),
                                          rec.getThreadName(),
                                          rec.getThrown() == null ? null : new ThrowableInformation(rec.getThrown()),
                                          rec.getNdc(),
                                          new LocationInfo(new Throwable(), rec.getLoggerClassName()),
                                          null);
                              }
                          

                           

                           

                          As a workaround, replace the log4j.jar in JBOSS_HOME/common/lib with 1.2.15 version of log4j.jar and see if it works.

                           

                          Ah, all these logging frameworks and abstractions - so much fun!

                          • 10. Re: Custom logger on AS 6
                            nickarls

                            *facepalm* Well, good thing is not just me ;-)

                             

                            Empty catch blocks are always nice. e.printStackTrace() is so hard to type...

                             

                            We need some abstraction for logger abstraction-abstractions. I'll try the log4j replacement trick and let you know. Was there some JIRA born from this?

                            • 11. Re: Custom logger on AS 6
                              jaikiran

                              Nicklas Karlsson wrote:

                               

                              Was there some JIRA born from this?

                              Haven't yet created one (been busy with a different task). So if you have some time, do create one. Else, I'll do it later tonight.

                              • 12. Re: Custom logger on AS 6
                                nickarls

                                Upgrading log4j didn't work. Well, I should really try on a clean server to make sure I haven't broken something else while trying to fix this...

                                • 13. Re: Custom logger on AS 6
                                  nickarls

                                  Correction, now I get hits on the logger!

                                  • 14. Custom logger on AS 6
                                    jaikiran

                                    Nicklas Karlsson wrote:

                                     

                                    Correction, now I get hits on the logger!

                                    Thanks for verifying that. So I guess, the easiest way to fix this is to upgrade to 1.2.15 of log4j in JBoss AS6. I'll file a JIRA for that.

                                    1 2 Previous Next