2

需要帮助在 JBoss 7.1.1 的standalone.xml 中设置 Log4j JDBCAppender

我已经尝试如下但不工作

<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>

错误日志

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

此错误是 DB 驱动程序加载问题,但如何解决此问题,或任何其他设置此错误的方法

4

1 回答 1

1

第一个问题是<driver/>标签不是<custom-handler/>.

第二个问题是 7.1.1.Final 不允许将 log4j 附加程序定义为自定义处理程序。这将适用于 EAP 6.x(6.2 已解决所有错误),但在不了解 log4j 如何实现它的数据库连接的情况下,引导可能存在潜在问题。例如,驱动程序可能尚未在 CP 上,因此您可能必须添加显式模块和依赖项。

您最好只创建一个简单的java.util.logging.Handlerorg.jboss.logmanager.ExtHandler处理您的数据库日志记录。它应该相当简单,并且不依赖于 log4j。您可以将处理程序添加到async-handler性能。

于 2014-01-02T16:52:46.040 回答