Jboss 7 log4j configuration - JDBCAppender

1.3k views Asked by At

Need help to setup Log4j JDBCAppender in standalone.xml in JBoss 7.1.1

I have tried as below but not working

<subsystem xmlns="urn:jboss:domain:logging:1.1">
....
....
....
<custom-handler name="DB" class="org.apache.log4j.jdbc.JDBCAppender" module="org.apache.log4j">
  <level name="ERROR"/>   
  <properties>
    <property name="URL">Data Base URL</property>
    <property name="driver">edb-jdbc14</property>
    <property name="user">username</property>
    <property name="password">password</property>
  </properties>
  <formatter>
  <pattern-formatter pattern="INSERT INTO log_dtl(application_type,thread,class,method,line_no,level,log_date,message_key,message_dtl,message_desc,message_meta_data) VALUES('APP','%t','%c','%M','%L','%p','%d{dd/MM/yyyy HH:mm:ss}','%X{MESSAGE_KEY}','%m','%X{MESSAGE_DESC}','%X{MESSAGE_META_DATA}')" />
  </formatter>
  <drivers>
      <driver name="edb-jdbc14" module="com.edb-jdbc14.postgresDriver">
         <driver-class>com.edb.Driver</driver-class>
      </driver>
  </drivers>                
</custom-handler>
....
....
</subsystem>

Error Log

14:56:16,881 ERROR [org.jboss.as.server] JBAS015956: Caught exception during boot: org.jboss.as.controller.persistence.ConfigurationPersistenceException: JBAS014676: Failed to parse configuration
    at org.jboss.as.controller.persistence.XmlConfigurationPersister.load(XmlConfigurationPersister.java:141) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.as.server.ServerService.boot(ServerService.java:266) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.as.controller.AbstractControllerService$1.run(AbstractControllerService.java:155) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]
    at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_02]
Caused by: java.lang.IllegalArgumentException: newValue is null
    at org.jboss.dmr.ModelNode.set(ModelNode.java:458) [jboss-dmr-1.1.1.Final.jar:1.1.1.Final]
    at org.jboss.as.logging.LoggingSubsystemParser.parsePropertyElement(LoggingSubsystemParser.java:898)
    at org.jboss.as.logging.LoggingSubsystemParser.parseCustomHandlerElement(LoggingSubsystemParser.java:610)
    at org.jboss.as.logging.LoggingSubsystemParser.readElement(LoggingSubsystemParser.java:169)
    at org.jboss.as.logging.LoggingSubsystemParser.readElement(LoggingSubsystemParser.java:113)
    at org.jboss.staxmapper.XMLMapperImpl.processNested(XMLMapperImpl.java:110) [staxmapper-1.1.0.Final.jar:1.1.0.Final]
    at org.jboss.staxmapper.XMLExtendedStreamReaderImpl.handleAny(XMLExtendedStreamReaderImpl.java:69) [staxmapper-1.1.0.Final.jar:1.1.0.Final]
    at org.jboss.as.server.parsing.StandaloneXml.parseServerProfile(StandaloneXml.java:894) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.as.server.parsing.StandaloneXml.readServerElement_1_1(StandaloneXml.java:330) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.as.server.parsing.StandaloneXml.readElement(StandaloneXml.java:127) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.as.server.parsing.StandaloneXml.readElement(StandaloneXml.java:100) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.staxmapper.XMLMapperImpl.processNested(XMLMapperImpl.java:110) [staxmapper-1.1.0.Final.jar:1.1.0.Final]
    at org.jboss.staxmapper.XMLMapperImpl.parseDocument(XMLMapperImpl.java:69) [staxmapper-1.1.0.Final.jar:1.1.0.Final]
    at org.jboss.as.controller.persistence.XmlConfigurationPersister.load(XmlConfigurationPersister.java:133) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]
    ... 3 more

This error is DB driver loading problem, but how to resolve this, or any alternative way to set up this

1

There are 1 answers

5
James R. Perkins On

The first issue is the <driver/> tag is not a valid tag for a <custom-handler/>.

The second issue is 7.1.1.Final will not allow log4j appenders to be defined as custom handlers. This would work with EAP 6.x (6.2 has all the bugs worked out), but without knowing much about how log4j implemented it's DB connection there could be potential issues with booting. For example the driver might not be on the CP yet so you might have to add an explicit module and dependency.

You might be best to just create a simple java.util.logging.Handler or org.jboss.logmanager.ExtHandler to handle your DB logging. It should be fairly simple to do and wouldn't rely on log4j. You could just add the handler to an async-handler for performance.