首页 > 解决方案 > 如何在 Spring Boot 中启用 Logback 访问?

问题描述

我正在尝试在 Spring Boot 应用程序中启用 logback-access 以记录所有命中应用程序的 http 请求。

我尝试过使用:https ://github.com/akihyro/logback-access-spring-boot-starter

添加示例中显示的 XML 文件没有任何作用,是否需要添加更多内容才能启用?

欢迎任何其他达到相同结果的建议:)

标签: springspring-bootlogging

解决方案


您仍然需要将 bean 连接到您的应用程序......就像这个代码片段将过滤器连接到您的应用程序:


@SpringBootApplication
public class MyApp {

    public static void main(String[] args) {
        SpringApplication.run(MyApp.class, args);
    }

    // ... your other methods here

    @Bean
    public CommonsRequestLoggingFilter logFilter() {
        CommonsRequestLoggingFilter filter = new CommonsRequestLoggingFilter();
        filter.setIncludeQueryString(true);

        return filter;
    }
}


推荐阅读