All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.raynigon.ecs.logging.access.server.TomcatAccessLogConfiguration Maven / Gradle / Ivy

package com.raynigon.ecs.logging.access.server;

import com.raynigon.ecs.logging.access.AccessLogProperties;
import com.raynigon.ecs.logging.access.logback.LogbackAccessValve;
import lombok.RequiredArgsConstructor;
import org.apache.catalina.Server;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;

import java.util.List;

@Configuration
@AutoConfiguration
@RequiredArgsConstructor
@Order(Ordered.HIGHEST_PRECEDENCE)
@AutoConfigureBefore(ServletWebServerFactoryAutoConfiguration.class)
@ConditionalOnClass(value = {Server.class, WebServerFactoryCustomizer.class})
@EnableConfigurationProperties(AccessLogProperties.class)
public class TomcatAccessLogConfiguration {

    @Value("${spring.application.name}")
    private String applicationName;

    private final AccessLogProperties config;

    @Bean
    public WebServerFactoryCustomizer tomcatAccessLogCustomizer(List accessValves) {
        return factory -> factory.addContextValves(accessValves.toArray(AccessValve[]::new));
    }

    @Bean
    public AccessValve accessLogValve() {
        return new LogbackAccessValve(config, applicationName);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy