关于SpringBoot使用LogBack写入文件 LOG_PATH_IS_UNDEFINED问题

使用<property name="LOG_PATH" value="./logs/${APP_NAME}"/>
出现LOG_PATH_IS_UNDEFINED

参考stackoverflow大佬回复

Before Spring Boot enviroment is prepared,
the Spring Boot main class or the SpringApplication will initialize the loggerfactory,
which will detect the default configuration file (logback.groovy, logback.xml, l
ogback-test.xml), but at this time the Spring Boot application is not started yet,
which means the variable LOG_PATH is not set.

因为Springboot加载Logfactory的优先级高与SpringBoot的环境准备,所以在加载logback.xml配置文件的时候Spring Boot Application还没有启动 所有在使用LOG_PATH的时候还没有初始化所以出现LOG_PATH_IS_UNDEFINED

我自己的解决办法
配置bootstrap.yml文件.boostrap.yml优先于application.yml加载

logging:
  file:
    path: ./logs/${spring.application.name}

然后再logback-spring.xml中使用 即可避免出现_IS_UNDEFINED

  <springProperty scop="context" name="LOG_PATH" source="logging.file.path" />

参考链接

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值