SpringBoot的jar包运行指定logback的配置文件路径

2022-05-17 1266点热度 0人点赞 0条评论

需求描述

SpringBoot打包好的jar文件,使用的logback作为日志系统,运行后,需要根据服务器实际情况,配置自定义的日志文件路径。

例如之前的jar文件是这样运行的:

java -Xms256M -Xmx1024M /opt/test/test-0.0.1-SNAPSHOT.jar

默认是会去找打包jar里面的类似logback-spring.xml这样的配置文件。现在的需求就是自定义个外部的logback-spring.xml文件,由这个文件来控制日志的一些配置信息,例如最后日志记录的文件路径等。

问题解决

我假设要运行的jar包放在/opt/test/test-0.0.1-SNAPSHOT.jar ,最后要指定的logback-spring.xml的文件路径是/opt/logback-spring.xml

往上大部分又说是这样,经过测试不行

java -Xms256M -Xmx1024M -Dconf.home="/opt/test/" -Dlogback.configurationFile=/opt/test/logback-spring.xml -jar /opt/test/test-0.0.1-SNAPSHOT.jar --spring.config.location=/opt/test/

经过踩坑和测试,如下的运行方式可以(使用的配置是:-Dlogging.config=/path/to/logback-spring.xml -jar)

/usr/bin/java -Xms256M -Xmx512M -Dconf.home="/opt/test/" -Dlogging.config=/opt/test/logback-spring.xml -jar /opt/test/test-0.0.1-SNAPSHOT.jar --spring.config.location=/opt/test/

 

admin

这个人很懒,什么都没留下

文章评论

您需要 登录 之后才可以评论