我通过使用以下内容放入META-INF目录jboss-deployment-structure.xml来覆盖默认的WildFly日志记录:
<jboss-deployment-structure>
<deployment>
<!-- exclude-subsystem prevents a subsystems deployment unit processors running on a deployment -->
<!-- which gives basically the same effect as removing the subsystem, but it only affects single deployment -->
<exclude-subsystems>
<subsystem name="logging"/>
</exclude-subsystems>
</deployment>
</jboss-deployment-structure>
并将logback.xml与以下内容放在一起:
<configuration debug="true">
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%-4relative [%thread] %-5level %logger{35} - %msg %n</pattern>
</encoder>
</appender>
<appender name="scriptgenToolAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>scriptgenTool.log</file>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>TRACE</level>
</filter>
<encoder>
<pattern>%d %logger{0}: %msg%n%ex{full}</pattern>
<outputPatternAsHeader>false</outputPatternAsHeader>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- daily rollover -->
<fileNamePattern>archive/scriptgenTool_.%d{dd-MM-yyyy}.log</fileNamePattern>
<maxHistory>3</maxHistory>
</rollingPolicy>
</appender>
<logger name="scriptGenTool" level="TRACE">
<appender-ref ref="STDOUT"/>
<appender-ref ref="scriptgenToolAppender"/>
</logger>
<root level="INFO">
<appender-ref ref="STDOUT"/>
<appender-ref ref="scriptgenToolAppender"/>
</root>
因此,所有日志都写入文件,但没有任何内容进入控制台(STDOUT appender)。是否可以使此日志控制台可打印?