我在standalone.xml文件中为同名的类别定义了两个处理程序,如下面的
<logger category="ab.cd" use-parent-handlers="false">
<level name="DEBUG" />
<handlers>
<handler name="abDebug" />
</handlers>
</logger>
<logger category="ab.cd" use-parent-handlers="true">
<level name="WARN" />
<handlers>
<handler name="abWarning" />
</handlers>
</logger>
但是当我尝试运行jboss 7时我会遇到异常
14:28:08,090 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_09]
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[143,4]
Message: JBAS014664: An element of this type named 'ab.cd' has already been declared
at org.jboss.as.controller.parsing.ParseUtils.duplicateNamedElement(ParseUtils.java:235) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.logging.LoggingSubsystemParser.parseLoggerElement(LoggingSubsystemParser.java:229)
at org.jboss.as.logging.LoggingSubsystemParser.readElement(LoggingSubsystemParser.java:149)
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
所以,我想知道这可能有两个相同类别的记录器吗?如果没有,那么在这种情况下如何将数据发送给两个不同的处理程序?
答案 0 :(得分:2)
您不能拥有两个定义了相同类别的记录器。记录器如何知道它应该使用哪个级别?您最好使用一个没有设置级别的记录器,并使用处理程序设置您想要记录的级别。
如下所示:
<file-handler name="abDebug" auto-flush="true">
<level name="DEBUG"/>
<file relative-to="jboss.server.log.dir" path="abDebug.log"/>
<append value="true"/>
</file-handler>
<file-handler name="abWarning" auto-flush="true">
<level name="WARN"/>
<file relative-to="jboss.server.log.dir" path="abWarning.log"/>
<append value="true"/>
</file-handler>
<logger category="ab.cd">
<handlers>
<handler name="abDebug" />
<handler name="abWarning" />
</handlers>
</logger>