首页 > 解决方案 > 如何在 application-{profile}.properties 文件中包含 log4j-{profile}.properties 文件

问题描述

我有两个特定于配置文件的 application.properties 文件(application-dev.properties 和 application-prod.properties)和两个 log4j.properties 文件。(Log4j-dev.properties 和 Log4j-prod.properties)。我需要在 application-dev.properties 文件中包含 log4j-dev.properties 文件。我怎样才能做到这一点?

标签: javaspring-bootlogging

解决方案


您可以使用logging.level.*. 使用spring-boot-starter-logging依赖。

logging.level.org.springframework=DEBUG
logging.level.com.howtodoinjava=DEBUG

#output to a temp_folder/file
logging.file=${java.io.tmpdir}/application.log

# Logging pattern for the console
logging.pattern.console= %d{yyyy-MM-dd HH:mm:ss} - %msg%n

# Logging pattern for file
logging.pattern.file= %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%

另一种解决方案是您可以使用链接到外部 log4j 配置文件logging.config=log4j.properties

因此,例如在application-dev.properties创建行中:

logging.config=classpath:Log4j-dev.properties

并在application-prod.properties创建行:

logging.config=classpath:Log4j-prod.properties

推荐阅读