title: Logging all Spring Boot http requests to the main log
body: <p>I want to log all http requests, minus actuator requests, in the main <code>spring.log</code> because I want to make them visible with <a href="https://github.com/codecentric/spring-boot-admin" rel="nofollow noreferrer">Spring Boot Admin</a> through the actuator API. I understand that I can configure the embedded Tomcat of Spring Boot to log http requests, but these will not be revealed either in the actuator API or Spring Boot Admin. I also realize I can use the default <code>/trace</code> configuration but I would like more than the last 100 requests.</p>
  
  <p>Currently, my strategy is to use a <code>HandlerInterceptorAdapter</code> to log the requests. <strong>The problem here is if a request is not authenticated it never makes it to the interceptor.</strong></p>
  
  <p>Interceptor:</p>
  
  <pre><code>@Component
  class HttpRequestLoggingInterceptor extends HandlerInterceptorAdapter {
  
      private static final Logger logger = LoggerFactory.getLogger(HttpRequestLoggingInterceptor.class)
  
      @Override
      void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
          logger.info("HTTP Request - ${request.localAddr} - \"${request.method} ${request.servletPath}\" ${response.status}")
      }
  
  }
  </code></pre>
  
  <p>AuthorizationServerConfigurerAdapter:</p>
  
  <pre><code>@Configuration
  @EnableAuthorizationServer
  class OAuth2Config extends AuthorizationServerConfigurerAdapter {
  
      @Autowired
      private HttpRequestLoggingInterceptor interceptor
  
      @Override
      void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
          endpoints.addInterceptor(interceptor)
      }
  
  }
  </code></pre>
  
  <p>WebMvcConfigurerAdapter:</p>
  
  <pre><code>@Configuration
  @Order
  class ApplicationConfig extends WebMvcConfigurerAdapter {
  
      @Autowired
      private HttpRequestLoggingInterceptor interceptor
  
      @Override
      void addInterceptors(InterceptorRegistry registry) {
          registry.addInterceptor(interceptor).excludePathPatterns("/actuator/**")
      }
  }
  </code></pre>
  
  <p>Thanks!</p>