我的 application.yml 是:
server:
tomcat:
accesslog:
enabled: true
basedir: my-tomcat
我们使用 spring boot 1.4.3.RELEASE,我想配置一个包含以下内容的 logback-access.xml (在 src/main/resources 下):
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- always a good activate OnConsoleStatusListener -->
<statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" />
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%h %l %u %user %date "%r" %s %b</pattern>
</encoder>
</appender>
<appender-ref ref="STDOUT" />
</configuration>
我可以在 my-tomcat 文件夹下看到 access_log.2017-01-03.log 文件,其中包含正确的访问日志,但在我的控制台上注意到,似乎未读取配置文件 logback-access.xml。
任何想法 ?
Eric
我是错误的还是 Spring Boot 本身不支持?
Source: https://github.com/spring-projects/spring-boot/issues/2609 https://github.com/spring-projects/spring-boot/issues/2609:
嘿,我正在尝试让 logback-access + tomcat 与 spring 一起使用
启动。有谁能够让这个开箱即用吗?或者是
需要设置一些必要的管道吗?
...
As a workaround, you can copy the access xml from the class path to the filesystem and run it there as part of your configuration class
Files.copy(this.getClass().getResourceAsStream("/logback-access.xml"),Paths.get("log-access.xml"),StandardCopyOption.REPLACE_EXISTING);
logbackValve.setFilename("log-access.xml");
Solution
Use spring-boot-ext-logback-access https://github.com/akihyro/logback-access-spring-boot-starter:
只需添加依赖项即可:
<dependency>
<groupId>net.rakugakibox.spring.boot</groupId>
<artifactId>logback-access-spring-boot-starter</artifactId>
<version>2.7.0</version>
</dependency>
编辑 - logback 1.1.6+ 的其他解决方案
On the 上面提到的 spring-boot 问题 https://github.com/spring-projects/spring-boot/issues/2609,有人发了这样的帖子:
从 logback 1.1.6 开始,不需要任何解决方法即可将 logback-access 配置文件作为资源加载。参考:http://jira.qos.ch/browse/LOGBACK-1069 http://jira.qos.ch/browse/LOGBACK-1069
您所要做的就是:logbackValve.setFilename("log-access.xml");
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)