springboot多环境日志配置,启动时logback-test.xml文件冲突导致启动失败:openFile(null,true) call failed. java.io.FileNotFoun...

  如题,在项目中用到了4个环境的日志配置文件,启动时在application.properties中指定环境,让springboot自动加载logback对应的配置文件:

  每个环境的日志目录都不一样,比如sit和test环境分别是:

 

  如果spring.profiles.active配置的是test,那么一切正常,非test环境,则启动失败。比如我现在配置spring.profiles.active=sit来启动联调环境,报错日志如下:

2020-01-10 14:32:33.579 |-ERROR [main] org.springframework.boot.SpringApplication [822] -| Application run failed
java.lang.IllegalStateException: Logback configuration error detected: 
ERROR in ch.qos.logback.core.rolling.RollingFileAppender[ERROR] - Failed to create parent directories for [/home/wlf/logs/prize/error-20200110.log]
ERROR in ch.qos.logback.core.rolling.RollingFileAppender[ERROR] - openFile(null,true) call failed. java.io.FileNotFoundException: /home/wlf/logs/prize/error-20200110.log (No such file or directory)
ERROR in ch.qos.logback.core.rolling.RollingFileAppender[CDR] - Failed to create parent directories for [/home/wlf/REPORT/send/prize20020000601809988202001101432.txt]
ERROR in ch.qos.logback.core.rolling.RollingFileAppender[CDR] - openFile(null,true) call failed. java.io.FileNotFoundException: /home/wlf/REPORT/send/prize20020000601809988202001101432.txt (No such file or directory)
        at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:167)
        at org.springframework.boot.logging.logback.LogbackLoggingSystem.reinitialize(LogbackLoggingSystem.java:220)
        at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithConventions(AbstractLoggingSystem.java:73)
        at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:60)
        at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:118)
        at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:289)
        at org.springframework.boot.context.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:264)
        at org.springframew
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
SpringBoot项目中,可以通过`java -jar`命令启动应用程序。如果想要加载`logback-spring.xml`配置文件,可以按照以下步骤进行操作: 1. 将`logback-spring.xml`配置文件放置在`src/main/resources`目录下。 2. 在`pom.xml`文件中添加`logback-classic`和`logback-spring`依赖。 ```xml <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>1.2.3</version> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-spring</artifactId> <version>1.2.3</version> </dependency> </dependencies> ``` 3. 在`application.properties`或`application.yml`文件中配置日志级别和日志文件路径。例如,在`application.yml`文件中添加以下内容: ```yaml logging: level: root: info file: name: logs/myapp.log ``` 4. 使用`java -jar`命令启动应用程序。`logback-spring.xml`配置文件将会自动加载并应用到应用程序中。 ```bash java -jar myapp.jar ``` 注意:如果在`logback-spring.xml`配置文件中定义了与`application.properties`或`application.yml`文件中相同的日志级别和日志文件路径,那么`application.properties`或`application.yml`文件中的配置将会覆盖`logback-spring.xml`配置文件中的配置
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值