我正在尝试向在WildFly 14.0.1服务器上运行的Spring应用程序中添加其他记录器。应用程序已使用 slf4j + log4j 进行日志记录。我试图在 log4j.xml 中添加一个额外的 appender ,并在 standalone.xml <中添加 periodic-rotating-file-handler / strong>,但没有成功。看来它们已被其他文件覆盖。
这是log4j.xml:
<!-- Console Appender -->
<appender name="STDOUT" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{HH:mm:ss,SSS} [%-5p] (%F:%L) - %m%n"/>
</layout>
</appender>
<!-- DailyRollingFile Appender -->
<appender name="DRFILE" class="org.apache.log4j.DailyRollingFileAppender">
<param name="Threshold" value="debug"/>
<param name="File" value="./log/terminal.log"/>
<param name="Append" value="true"/>
<param name="DatePattern" value="'.'yyy-MM-dd"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{dd-MM-yyyy HH:mm:ss,SSS} [%-5p] (%F:%L) - %m%n"/>
</layout>
</appender>
<appender name="DRCSVFILE" class="org.apache.log4j.DailyRollingFileAppender">
<param name="Threshold" value="debug"/>
<param name="File" value="./log/requests.log"/>
<param name="Append" value="true"/>
<param name="DatePattern" value="'.'yyy-MM-dd"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{dd-MM-yyyy HH:mm:ss,SSS} [%-5p] (%F:%L) - %m%n"/>
</layout>
</appender>
<logger name="com.terminal.spring.logging" >
<level value="INFO"/>
<appender-ref ref="DRCSVFILE" />
</logger>
<root>
<priority value="INFO"/>
<appender-ref ref="STDOUT"/>
<appender-ref ref="DRFILE"/>
</root>
WildFly的standalone.xml代码段:
<subsystem xmlns="urn:jboss:domain:logging:6.0">
<console-handler name="CONSOLE">
<level name="DEBUG"/>
<formatter>
<named-formatter name="CONSOLE-PATTERN"/>
</formatter>
</console-handler>
<periodic-rotating-file-handler name="FILE" autoflush="true">
<level name="DEBUG"/>
<formatter>
<named-formatter name="PATTERN"/>
</formatter>
<file relative-to="jboss.server.log.dir" path="terminal.log"/>
<suffix value=".yyyy-MM-dd"/>
<append value="true"/>
</periodic-rotating-file-handler>
<periodic-rotating-file-handler name="CSVFILE" autoflush="true">
<level name="DEBUG"/>
<formatter>
<named-formatter name="PATTERN"/>
</formatter>
<file relative-to="jboss.server.log.dir" path="requests.log"/>
<suffix value=".yyyy-MM-dd"/>
<append value="true"/>
</periodic-rotating-file-handler>
<logger category="com.arjuna">
<level name="WARN"/>
</logger>
<logger category="org.jboss.as.config">
<level name="INFO"/>
</logger>
<logger category="com.terminal">
<level name="${env.DEBUG_LEVEL:INFO}"/>
</logger>
<logger category="sun.rmi">
<level name="WARN"/>
</logger>
<root-logger>
<level name="INFO"/>
<handlers>
<handler name="CONSOLE"/>
<handler name="FILE"/>
</handlers>
</root-logger>
<formatter name="PATTERN">
<pattern-formatter pattern="%d{dd-MM-yyyy HH:mm:ss,SSS} [%-5p] (%F:%L) - %m%n"/>
</formatter>
<formatter name="CONSOLE-PATTERN">
<pattern-formatter pattern="%K{level}%d{HH:mm:ss,SSS} [%-5p] (%F:%L) - %m%n"/>
</formatter>
</subsystem>
但是,terminal.log已成功创建,但request.log未成功创建。
有人知道吗?
答案 0 :(得分:0)
standalone.xml文件中缺少此附加的记录器定义:
<logger category="com.terminal.spring.logging">
<level name="DEBUG"/>
<handlers>
<handler name="CSVFILE"/>
</handlers>
</logger>