gpt4 book ai didi

spring-boot - 使用多个配置文件配置 logback

转载 作者:行者123 更新时间:2023-12-03 07:52:22 24 4
gpt4 key购买 nike

我正在尝试通过 springboot 下的配置文件拆分我的 logback.xml,这是我的方法:

logback-prod.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml" />
<property name="LOG_FILE" value="${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:- ${java.io.tmpdir:-/tmp}}/}spring.log}"/>
<include resource="org/springframework/boot/logging/logback/file- appender.xml" />

<root level="INFO">
<appender-ref ref="CONSOLE" />
</root>
</configuration>

logback-dev.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml" />
<include resource="org/springframework/boot/logging/logback/console-appender.xml" />

<root level="DEBUG">
<appender-ref ref="CONSOLE" />
</root>

logback.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="logback-${spring.profiles.active}.xml"/>

<root level="INFO">
<appender-ref ref="FILE" />
<appender-ref ref="CONSOLE" />
</root>

最后使用:
-Dspring.profiles.active=dev
or
-Dspring.profiles.active=prod

我进入控制台:
13:01:44,673 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@2:16 - no  applicable action for [configuration], current ElementPath  is [[configuration][configuration]]
13:01:44,674 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@3:81 - no applicable action for [include], current ElementPath is [[configuration][configuration][include]]
13:01:44,674 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@4:89 - no applicable action for [include], current ElementPath is [[configuration][configuration][include]]
13:01:44,674 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@6:25 - no applicable action for [root], current ElementPath is [[configuration][configuration][root]]
13:01:44,674 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@7:39 - no applicable action for [appender-ref], current ElementPath is [[configuration][configuration][root][appender-ref]]
13:01:44,675 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to INFO

最佳答案

Spring boot documentation推荐使用 logback-spring.xml而不是 logback.xml在其中您可以使用 spring 配置文件标签:

<configuration>
<springProfile name="workspace">
...
</springProfile>
<springProfile name="dev,prd">
...
</springProfile>
</configuration>

关于spring-boot - 使用多个配置文件配置 logback,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35651241/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com