Spring Boot中实现logback多环境日志配置

在Spring Boot中,可以在logback.xml中的springProfile标签中定义多个环境
logback.xml:

<springProfile name="production">
    <root level="DEBUG">
        <appender-ref ref="STDOUT"/>

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

    </root>
</springProfile>

现在想要将logback.xml文件拆分为logback-production.xml,logback-dev.xml两个文件(logback-{profile}.xml),而不是定义在同一个文件中。然后应用会根据profile确定使用哪个配置文件。

application.properties里面配置:

logging.config: classpath:logback-${spring.profiles.active}.xml

启动时指定:

java -jar xxx.jar --spring.profiles.active=dev

也可以在application.properties指定:

spring.profiles.active=dev

参考:

https://docs.spring.io/spring-boot/docs/1.5.7.RELEASE/reference/htmlsingle/#boot-features-custom-log-configuration(官方配置参考,一切答案都在这里)

http://blog.csdn.net/m0_37895333/article/details/72457007

http://www.cnblogs.com/wuyechun/p/6800956.html

http://blog.csdn.net/vitech/article/details/53812137

原文地址:https://www.cnblogs.com/EasonJim/p/7801549.html