用于Spring Boot的logging.config配置

Ara*_*yan 5 logging spring log4j logback spring-boot

我想在我的Spring Boot应用程序中配置log4j.xml文件的位置。为此,我已将logging.config属性添加到我的application.properties配置中,指示log4j.xml文件路径。但是似乎此属性被忽略。但是它应该可以根据春季启动文档工作:

logging.config= # location of config file (default classpath:logback.xml for logback)
Run Code Online (Sandbox Code Playgroud)

我做错什么了吗?

Ali*_*ani 4

Spring Boot 包含一些启动器,如果您想排除或交换特定的技术方面,可以使用这些启动器。如果您要在类路径中使用add logback,则默认使用它。例如,对于 Maven,它会是这样的:log4jspring-boot-starter-log4j

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-log4j2</artifactId>
            <version>1.2.4.RELEASE</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

对于 log4j 1.x:

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-log4j</artifactId>
            <version>1.2.4.RELEASE</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

然后添加logging.config到您的application.properties

logging.config = classpath:path/to/log4j.xml
Run Code Online (Sandbox Code Playgroud)