Version 3

    Log4jSocketServer

    The org.jboss.logging.Log4jSocketServer is an mbean service that allows one to collect output from multiple log4j clients (including jboss servers) that are using the org.apache.log4j.net.SocketAppender. The Log4jSocketServer creates a server socket to accept SocketAppender connections, and logs incoming messages based on the local log4j.xml configuration.

     

    You can create a minimal jboss configuration that includes a Log4jSocketServer to act as your log server. An example Log4jSocketServer mbean configuration that could be added the conf/jboss-service.xml is:

       <mbean code="org.jboss.logging.Log4jSocketServer"
          name="jboss.system:type=Log4jService,service=SocketServer">
          <attribute name="Port">12345</attribute>
          <attribute name="BindAddress">${jboss.bind.address}</attribute>
       </mbean>
    

     

    The Log4jSocketServer adds an MDC entry under the key 'host' which includes the client socket InetAddress.getHostName value on every client connection. This allows you to differentiate logging output based on the client hostname using the MDC pattern. For example, to augment the log server console output with the logging client socket hostname, add %X as shown here:

       <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
          <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"></errorHandler>
          <param name="Target" value="System.out"/>
          <param name="Threshold" value="INFO"/>
    
          <layout class="org.apache.log4j.PatternLayout">
             <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1},%X{host}] %m%n"/>
          </layout>
       </appender>
    

     

    All other jboss servers that should send log messages to the log server would add an appender configuration that uses the SocketAppender. An example log4j.xml appender for the Log4jSocketServer is:

       <appender name="SOCKET" class="org.apache.log4j.net.SocketAppender">
          <param name="Port" value="12345"/>
          <param name="RemoteHost" value="loghost"/>
          <param name="ReconnectionDelay" value="60000"/>
          <param name="Threshold" value="INFO"/>
       </appender>