Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加LoggingFactoryBeanCustomizers类来集合注入LoggingFactoryBeanCustomizer实例 #59

Closed
hengboy opened this issue Aug 25, 2020 · 1 comment · Fixed by #49
Closed
Assignees
Labels
kind/feature New features

Comments

@hengboy
Copy link
Member

hengboy commented Aug 25, 2020

通过LoggingFactoryBeanCustomizers类内通过集合的形式来注入LoggingFactoryBeanCustomizer,并且针对LoggingFactoryBean实例进行修改。

@hengboy hengboy added the kind/feature New features label Aug 25, 2020
@hengboy hengboy self-assigned this Aug 25, 2020
@hengboy hengboy linked a pull request Aug 25, 2020 that will close this issue
@hengboy
Copy link
Member Author

hengboy commented Aug 25, 2020

LoggingFactoryBeanCustomizers 类定义

/**
 * The {@link LoggingFactoryBeanCustomizer} collection processing class
 *
 * @author 恒宇少年
 */
public class LoggingFactoryBeanCustomizers {
    private List<LoggingFactoryBeanCustomizer> customizers;

    public LoggingFactoryBeanCustomizers(List<LoggingFactoryBeanCustomizer> customizers) {
        this.customizers = (customizers != null) ? new ArrayList<>(customizers) : Collections.emptyList();
    }

    /**
     * Customize the specified {@link LoggingFactoryBean}. Locates all
     * {@link LoggingFactoryBeanCustomizer} beans able to handle the specified instance and
     * invoke {@link LoggingFactoryBeanCustomizer#customize(LoggingFactoryBean)} on them.
     *
     * @param factoryBean the logging factory bean to customize
     * @return the factory bean
     */
    public LoggingFactoryBean customize(LoggingFactoryBean factoryBean) {
        LambdaSafe.callbacks(LoggingFactoryBeanCustomizer.class, this.customizers, factoryBean)
            .withLogger(LoggingFactoryBeanCustomizer.class).invoke((customizer) -> customizer.customize(factoryBean));
        return factoryBean;
    }
}

使用示例

/**
 * {@link LoggingFactoryBeanCustomizer}实现类
 * 新增排除日志拦截输出的路径
 *
 * @author 恒宇少年
 */
@Component
@Order(2)
public class AppendIgnorePathCustomizer implements LoggingFactoryBeanCustomizer {
    @Override
    public void customize(LoggingFactoryBean factoryBean) {
        factoryBean.getIgnorePaths().add("/test");
    }
}

注意事项:如果存在多个LoggingFactoryBeanCustomizer,可以通过@Order注解来定义执行的顺序,值越小执行越靠前

@hengboy hengboy closed this as completed Aug 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature New features
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant