我正在使用 JBoss AS 7.0.2.Final 并且没有机会改变它。
我尝试配置standalone.xml 为不同的类别创建不同的日志文件。我的问题是:每个记录器的输出都正确附加在指定的文件上,但也写在 server.log 文件上。
这是我的整个日志子系统配置:
<subsystem xmlns="urn:jboss:domain:logging:1.1">
<console-handler name="CONSOLE" autoflush="true">
<level name="INFO"/>
<formatter>
<pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
</formatter>
</console-handler>
<periodic-rotating-file-handler name="FILE" autoflush="true">
<level name="INFO"/>
<formatter>
<pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
</formatter>
<file relative-to="jboss.server.log.dir" path="server.log"/>
<suffix value=".yyyy-MM-dd"/>
<append value="true"/>
</periodic-rotating-file-handler>
<periodic-rotating-file-handler name="REQUEST" autoflush="true">
<level name="INFO"/>
<formatter>
<pattern-formatter pattern="%m%n"/>
</formatter>
<file path="/Logs/requests.log"/>
<suffix value=".yyyy-MM-dd-HH"/>
<append value="true"/>
</periodic-rotating-file-handler>
<periodic-rotating-file-handler name="ALARMS" autoflush="true">
<level name="INFO"/>
<formatter>
<pattern-formatter pattern="%m%n"/>
</formatter>
<file path="/Logs/alarms.log"/>
<suffix value=".yyyy-MM-dd-HH"/>
<append value="true"/>
</periodic-rotating-file-handler>
<logger category="com.maucho.alarm" use-parent-handlers="false">
<level name="INFO"/>
<handlers>
<handler name="ALARMS"/>
</handlers>
</logger>
<logger category="com.maucho.request" use-parent-handlers="false">
<level name="INFO"/>
<handlers>
<handler name="REQUEST"/>
</handlers>
</logger>
<logger category="com.arjuna">
<level name="WARN"/>
</logger>
<logger category="org.apache.tomcat.util.modeler">
<level name="WARN"/>
</logger>
<logger category="sun.rmi">
<level name="WARN"/>
</logger>
<logger category="com.hp.autopassj">
<level name="WARN"/>
</logger>
<logger category="org.jboss.as.server.deployment">
<level name="ERROR"/>
</logger>
<root-logger>
<level name="INFO"/>
<handlers>
<handler name="CONSOLE"/>
<handler name="FILE"/>
</handlers>
</root-logger>
</subsystem>
启动 AS 时,standalone.xml 文件将被覆盖,并将没有属性 use-parent-handlers="false" 的记录器标记替换为空,将行为设置为其默认值 use-parent-handlers="true":
<subsystem xmlns="urn:jboss:domain:logging:1.1">
<console-handler name="CONSOLE" autoflush="true">
<level name="INFO"/>
<formatter>
<pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
</formatter>
</console-handler>
<periodic-rotating-file-handler name="FILE" autoflush="true">
<level name="INFO"/>
<formatter>
<pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
</formatter>
<file relative-to="jboss.server.log.dir" path="server.log"/>
<suffix value=".yyyy-MM-dd"/>
<append value="true"/>
</periodic-rotating-file-handler>
<periodic-rotating-file-handler name="REQUEST" autoflush="true">
<level name="INFO"/>
<formatter>
<pattern-formatter pattern="%m%n"/>
</formatter>
<file path="/Logs/requests.log"/>
<suffix value=".yyyy-MM-dd-HH"/>
<append value="true"/>
</periodic-rotating-file-handler>
<periodic-rotating-file-handler name="ALARMS" autoflush="true">
<level name="INFO"/>
<formatter>
<pattern-formatter pattern="%m%n"/>
</formatter>
<file path="/Logs/alarms.log"/>
<suffix value=".yyyy-MM-dd-HH"/>
<append value="true"/>
</periodic-rotating-file-handler>
<logger category="com.maucho.alarm">
<level name="INFO"/>
<handlers>
<handler name="ALARMS"/>
</handlers>
</logger>
<logger category="com.maucho.request">
<level name="INFO"/>
<handlers>
<handler name="REQUEST"/>
</handlers>
</logger>
<logger category="com.arjuna">
<level name="WARN"/>
</logger>
<logger category="org.apache.tomcat.util.modeler">
<level name="WARN"/>
</logger>
<logger category="sun.rmi">
<level name="WARN"/>
</logger>
<logger category="com.hp.autopassj">
<level name="WARN"/>
</logger>
<logger category="org.jboss.as.server.deployment">
<level name="ERROR"/>
</logger>
<root-logger>
<level name="INFO"/>
<handlers>
<handler name="CONSOLE"/>
<handler name="FILE"/>
</handlers>
</root-logger>
</subsystem>
文档很差,说我只需要输入参数 use-parent-handlers="false" 但它不起作用。
另外,我还使用 org.apache.commons.logging.LogFactory 将我的代码 org.apache.log4j.Logger 更改为 org.apache.commons.logging.Log 并得到相同的结果,在两个文件(/Logs/ requests.log 或 /Logs/alarms.log AND server.log)。
我的参考资料: https: //community.jboss.org/message/731527 http://commons.apache.org/logging/guide.html