3 Replies Latest reply: Apr 11, 2012 5:34 AM by White_Sox RSS

jboss-6.1.0 Final + Log4J SyslogAppender

White_Sox Newbie

In deploy/jboss-logging.xml I have the following configuration:

 

 

<log4j-appender name="SYSLOG" class="org.apache.log4j.net.SyslogAppender">

      <error-manager>

         <only-once/>

      </error-manager>

 

        <level name="DEBUG"/>

 

      <properties>

         <property name="facility">USER</property>

         <property name="facilityPrinting">false</property>

         <property name="syslogHost">localhost</property>

         <property name="header">true</property>

      </properties>

 

      <formatter>

         <pattern-formatter pattern="%p %d{dd MMM yyyy HH:mm:ss,SSS} %c - %m%n"/>

      </formatter>

   </log4j-appender>

 

 

The message gets through to rsyslog, but only the "%m" part gets there. I've tried with different patterns and also commented out the <formatter> part and the result is the same.
Using the command  logger -p FACILITY "MESSAGE" I can test rsyslog and it's working fine, so my understanding is that JBoss + Log4j is not sending the full log message.

 

Does anybody have any idea about this?

 

Thank you !

  • 1. Re: jboss-6.1.0 Final + Log4J SyslogAppender
    White_Sox Newbie

    The problem is with the org.apache.log4j.net.SyslogAppender class. The class is only handling part of the message, ignoring information such as timestamp and debug level.
    The solution is to extend the class and override the handling methods.

  • 2. Re: jboss-6.1.0 Final + Log4J SyslogAppender
    Rob Breault Newbie

    I see you say the solution is to extend the class and override the handling methods? Is this also true for Jboss-5.0.0GA as I have also set this up and get the following

     

    Run this for a test

     

    logger –p local0.warning “This space intentionally left blank”

     

    Then look at my remote system and have the following

     

    2012-04-10T15:50:26-06:00 atgbcc1 root: –p local0.warning “This space intentionally left blank”

     

    So I can see that I can write to that log without issues.

     

    I have setup my jboss-log4j.xml as so

     

       <appender name="SYSLOG" class="org.apache.log4j.net.SyslogAppender">

         <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>

         <param name="Facility" value="local0"/>

         <param name="FacilityPrinting" value="true"/>

         <param name="Header" value="true"/>

         <param name="SyslogHost" value="localhost"/>

         <layout class="org.apache.log4j.PatternLayout">

          <param name="ConversionPattern" value="%-4r [%t] %-5p %X{profileId} %X{orderId} %X{sessionId} %c %x - %m%n"/>

         </layout>

       </appender>

     

    So I am curious if I just missed something or if I have do as you post extend the class which I am not sure how to do.

     

    Thanks,

     

    Rob

  • 3. Re: jboss-6.1.0 Final + Log4J SyslogAppender
    White_Sox Newbie

    My post refers to 6.1.0. I don't know about Jboss-5.0.0GA .

    If you're not receiving the full Log4jJ message on syslog, you problably will have to extend the  org.apache.log4j.net.SyslogAppender class and override the "append" method.

    You do this by creating a new JAR where you extend the class and override the method, such as:

     

    public class NewLog4jAppender extends SyslogAppender {

     

     

    @Override

        public void append(LoggingEvent event) {

     

    ........ (create newEvent)

     

    super.append(newEvent)

     

     

    }

     

    You can extract the log information from the event parameter and create a new LoggingEvent where you add all the data you need. Then you  call the append from the parent class.

    After doing this, you'll have to call your new class on jboss-log4j.xml:

     

    <appender name="SYSLOG" class="NewLog4jAppender">

     

    Hope this helps