在Spring Boot 1.3中,我们只能将访问日志记录到文件系统中。是否有办法实际使用自定义记录器(如log4j2)来记录访问日志?
我目前正在使用Undertow与Spring Boot,但检查了Spring Boot源代码后发现,Undertow记录器是使用DefaultAccessLogReceiver进行初始化的,该记录器会将日志写入文件。如果可能,我想使用AccessLogHandler并避免编写记录访问的Web过滤器。
除了编写拉取请求外,是否有任何简单的解决方法?
在Spring Boot 1.3中,我们只能将访问日志记录到文件系统中。是否有办法实际使用自定义记录器(如log4j2)来记录访问日志?
我目前正在使用Undertow与Spring Boot,但检查了Spring Boot源代码后发现,Undertow记录器是使用DefaultAccessLogReceiver进行初始化的,该记录器会将日志写入文件。如果可能,我想使用AccessLogHandler并避免编写记录访问的Web过滤器。
除了编写拉取请求外,是否有任何简单的解决方法?
package io.undertow.server.handlers.accesslog;
public class DefaultAccessLogReceiver implements AccessLogReceiver {
public void logMessage(final String message) {
// TODO: log with log4j
}
}
Spring Boot没有强制的日志依赖,但是有许多commons-logging API的实现可供选择。如果要使用Logback,则需要将其包含在类路径中,同时需要一些针对commons-logging的绑定。最简单的方法是通过启动器poms来完成,这些启动器都依赖于spring-boot-starter-logging。对于Web应用程序,您只需要spring-boot-starter-web,因为它会在传递依赖项中依赖于日志启动器。例如,在Maven中:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j</artifactId>
</dependency>