java – 我可以通过编程方式设置Spring Boot的日志位置吗?
可以使用application.properties中的logging.file属性设置Spring Boot的日志记录位置.但是我想以编程方式设置位置.我的逻辑不是基于任何Spring bean,只是基于反复试验,因为相同的代码必须在可能具有不同安全配置的不同环境中运行.
根据the documentation:
Since logging is initialized before the ApplicationContext is created, it isn’t possible to control logging from @PropertySources in Spring @Configuration files. System properties and the conventional Spring Boot external configuration files work just fine.) [sic]
所以我知道我不能使用@Configuration文件,但我可以使用其他方式,如静态初始化器,仍然设法以编程方式设置日志记录位置?
(注意:我个人使用SLF4J和Logback,但Spring Boot的日志框架旨在应对不同的日志外观/实现,实际上在内部使用Commons Logging.)
(注2:有些人已经注意到这是another question的副本……但是这个问题似乎更多地是关于配置实际的日志记录实现,而这个问题是关于Spring Boot自己的配置.事实上,我无法立即确定那些答案如何解决我的具体问题,正如相关答案下面的评论中所述.其他问题的答案主要集中在如何在正确的上下文初始化点上加载代码,而我的问题是关于如何设置日志记录位置.)