Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JBoss AS 7 configure logging to Syslog Appender

In a previous version of Jboss I was able to configure a SYSLOG appender with the following configuration in jboss-log4j.xml:

<appender name="SYSLOG" class="org.apache.log4j.net.SyslogAppender">
  <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
  <param name="Facility" value="LOCAL7"/>
  <param name="FacilityPrinting" value="true"/>
  <layout class="org.apache.log4j.PatternLayout">
    <param name="ConversionPattern" value="[%d{ABSOLUTE},%c{1}] %m%n"/>
  </layout>
</appender>

Now I've upgraded to Jboss AS 7 and it seems like this should go in the $JBOSS_HOME/standalone/configuration/standalone.xml but the syntax is different.

My question is: How do I configure Jboss AS 7 to use a SYSLOG appender?

like image 990
Jarred Olson Avatar asked Jan 17 '23 19:01

Jarred Olson


1 Answers

log4j is no longer used in JBoss AS 7 there for there is no syslog appender. You would have to find or develop a custom java.util.logging.Handler if you want something similar.

Once the handler is created it's probably best to make it a module. Let's say the handler was called com.example.logging.SysLogHandler. In $JBOSS_HOME/modules create a directory called com/example/logging/main. In that directory place your library and create an module.xml file, see another module for an example.

module.xml example:

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="com.example.logging">
    <resources>
        <resource-root path="sys-log.jar"/>
    </resources>
    <dependencies>
         <!-- Insert any dependencies here like the example below -->
         <!-- <module name="org.jboss.logmanager"/> -->
    </dependencies>
</module>

You can now edit the standalone.xml to add a custom handler.

<subsystem xmlns="urn:jboss:domain:logging:1.1">
    ...
    <!-- A syslog handler -->
    <custom-handler name="syslog" class="com.example.logging.SysLogHandler" module="com.example.logging">
        <level name="INFO"/>
        <formatter>
            <pattern-formatter pattern="%d{MMM dd HH:mm:ss} %-5p [%c] (%t) %s%n"/>
        </formatter>
        <properties>
            <!-- Set any properties that can accessed through setter methods -->
            <property name="autoFlush" value="true"/>
        </properties>
    </custom-handler>
    ...
    <root-logger>
        <level name="INFO"/>
        <handlers>
            <handler name="CONSOLE"/>
            <handler name="FILE"/>
            <handler name="syslog"/>
        </handlers>
    </root-logger>
</subsystem>
like image 112
James R. Perkins Avatar answered Mar 04 '23 02:03

James R. Perkins