我在Spring Boot应用程序中为LogBack定义了一对自定义记录器。我们的想法是将所有日志记录发送到一个文件,而不是默认情况下由Spring Boot提供的标准控制台输出。我所看到的是,日志记录同时发送到自定义文件和控制台,我找不到任何理由。所有记录到两个自定义appender的都是DEBUG和/或TRACE级别。我设置了logging.level.root = INFO,认为这会阻止此日志记录显示,但这没有帮助。
我确实配置了标准的Spring Boot日志记录,以便在应用程序中使用。所以logging.path和logging.file都已设置。
任何帮助表示感谢。
这是我的自定义logback-spring.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<!--
LogBack configuration used by all services to create separate files for TRACE and SOAP logs.
-->
<configuration>
<!-- Include the basic Spring-Boot logback configuration. -->
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<!-- An appender and logger for TRACE logging of method calls -->
<appender name="TraceLoggingAppender" class="ch.qos.logback.core.FileAppender">
<file>${LOG_PATH}/logs/trace.log</file>
<encoder>
<pattern>${FILE_LOG_PATTERN}</pattern>
</encoder>
</appender>
<logger name="TraceLogging" additivity="false" level="trace">
<appender-ref ref="TraceLoggingAppender"/>
</logger>
<!-- An appender and logger for SOAP envelope logging -->
<appender name="SoapLoggingAppender" class="ch.qos.logback.core.FileAppender">
<file>${LOG_PATH}/logs/soap.log</file>
<encoder>
<pattern>${FILE_LOG_PATTERN}</pattern>
</encoder>
</appender>
<logger name="SoapLogging" additivity="false" level="debug">
<appender-ref ref="SoapLoggingAppender"/>
</logger>
</configuration>
一个示例用法:
private static final Log LOG = LogFactory.getLog("SoapLogging");
...
LOG.debug(soapMessage);
答案 0 :(得分:0)
而不是像here
那样包括base.xml
包括defaults.xml
<include resource="org/springframework/boot/logging/logback/defaults.xml" />