package com.esv.freight.file.config;

import com.esv.freight.file.common.filter.LogbackFilter;
import com.esv.freight.file.common.filter.RestLogFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @description: 注册请求Filter
 * @project: SpringCloudTemplate
 * @name: com.esv.springcloud.template.web.config.FilterConfig
 * @author: 黄朝斌
 * @email: huangchaobin@esvtek.com
 * @createTime: 2020/03/09 17:47
 * @version:1.0
 */
@Configuration
public class LogFilterConfig {

    private static final String URL = "/*";

    @Bean
    public FilterRegistrationBean<LogbackFilter> logbackFilterRegister() {
        FilterRegistrationBean<LogbackFilter> registration = new FilterRegistrationBean<>();
        registration.setFilter(new LogbackFilter());
        registration.addUrlPatterns(URL);
        registration.setOrder(Integer.MIN_VALUE);
        return registration;
    }

    @Bean
    public FilterRegistrationBean<RestLogFilter> restLogFilterRegister() {
        FilterRegistrationBean<RestLogFilter> filterRegistrationBean=new FilterRegistrationBean<>();
        filterRegistrationBean.setFilter(new RestLogFilter());
        filterRegistrationBean.addUrlPatterns(URL);
        filterRegistrationBean.setOrder(Integer.MIN_VALUE + 1);
        return filterRegistrationBean;
    }
}
