Java 如何根据生命周期环境使用不同的文件名模式
如何根据活动的spring引导配置文件使用不同版本的logback.xmlJava 如何根据生命周期环境使用不同的文件名模式,java,logging,logback,spring-logback,Java,Logging,Logback,Spring Logback,如何根据活动的spring引导配置文件使用不同版本的logback.xml src/main/resources/logback.xml src/main/resources/logback-qa.xml src/main/resources/logback-staging.xml src/main/resources/logback-production.xml 我的目的是根据环境和文件路径单独更改fileNamePattern,如果使用单个文件更容易实现的话,我不希望创建其他文件 <
src/main/resources/logback.xml
src/main/resources/logback-qa.xml
src/main/resources/logback-staging.xml
src/main/resources/logback-production.xml
我的目的是根据环境和文件路径单独更改fileNamePattern,如果使用单个文件更容易实现的话,我不希望创建其他文件
<fileNamePattern>logs/app.%d{yyyy-MM-dd}.log</fileNamePattern>
<fileNamePattern>logs/app-qa.%d{yyyy-MM-dd}.log</fileNamePattern>
<fileNamePattern>logs/app-staging.%d{yyyy-MM-dd}.log</fileNamePattern>
<fileNamePattern>/logs/app-production.%d{yyyy-MM-dd}.log</fileNamePattern>
logs/app.%d{yyyy-MM-dd}.log
日志/应用程序qa.%d{yyyy-MM-dd}.log
日志/应用暂存。%d{yyyy-MM-dd}.log
/日志/应用程序生产。%d{yyyy-MM-dd}.log
logback-spring.xml支持springProfile标记,建议使用logback-spring.xml而不是logback.xml。
您可以在logback-spring.xml中使用springProfile标记,如下所示:
<springProfile name="staging">
<!-- configuration to be enabled when the "staging" profile is active -->
</springProfile>
<springProfile name="dev | staging">
<!-- configuration to be enabled when the "dev" or "staging" profiles are active -->
</springProfile>
<springProfile name="!production">
<!-- configuration to be enabled when the "production" profile is not active -->
</springProfile>