Skip to content

Commit 8982b23

Browse files
committed
添加自定义配置LoggingFactoryBean接口,实现该接口可完成对LoggingFactoryBean自定义配置
1 parent 6bd659b commit 8982b23

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

api-boot-project/api-boot-autoconfigure/src/main/java/org/minbox/framework/api/boot/autoconfigure/logging/ApiBootLoggingAutoConfiguration.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
import org.springframework.context.annotation.Configuration;
3535
import org.springframework.context.annotation.Import;
3636
import org.springframework.scheduling.annotation.EnableAsync;
37+
import org.springframework.util.ObjectUtils;
38+
39+
import java.util.List;
3740

3841
import static org.minbox.framework.api.boot.autoconfigure.logging.ApiBootLoggingProperties.API_BOOT_LOGGING_PREFIX;
3942

@@ -79,14 +82,20 @@ public ApiBootLoggingAutoConfiguration(ApiBootLoggingProperties apiBootLoggingPr
7982
*/
8083
@Bean
8184
@ConditionalOnMissingBean
82-
public LoggingFactoryBean loggingFactoryBean(ObjectProvider<LoggingAdminDiscovery> loggingAdminDiscoveryObjectProvider) {
85+
public LoggingFactoryBean loggingFactoryBean(ObjectProvider<LoggingAdminDiscovery> loggingAdminDiscoveryObjectProvider,
86+
ObjectProvider<List<LoggingFactoryBeanCustomizer>> customizerObjectProvider) {
8387
LoggingFactoryBean factoryBean = new LoggingFactoryBean();
8488
factoryBean.setIgnorePaths(apiBootLoggingProperties.getIgnorePaths());
8589
factoryBean.setReportAway(apiBootLoggingProperties.getReportAway());
8690
factoryBean.setNumberOfRequestLog(apiBootLoggingProperties.getReportNumberOfRequestLog());
8791
factoryBean.setReportInitialDelaySecond(apiBootLoggingProperties.getReportInitialDelaySecond());
8892
factoryBean.setReportIntervalSecond(apiBootLoggingProperties.getReportIntervalSecond());
8993
factoryBean.setLoggingAdminDiscovery(loggingAdminDiscoveryObjectProvider.getIfAvailable());
94+
95+
List<LoggingFactoryBeanCustomizer> customizers = customizerObjectProvider.getIfAvailable();
96+
if (!ObjectUtils.isEmpty(customizers)) {
97+
customizers.stream().forEach(customizer -> customizer.customize(factoryBean));
98+
}
9099
return factoryBean;
91100
}
92101

@@ -161,7 +170,7 @@ public LoggingAdminNotice loggingAdminNotice(LoggingFactoryBean factoryBean) {
161170
* Logging Report Scheduled Task Job
162171
* When the configuration parameter "api.boot.logging.report-away=timing" is configured,
163172
* the creation timing task is performed to report log information to admin node
164-
* {@link ApiBootLoggingProperties#getReportAway}
173+
* {@link ApiBootLoggingProperties}
165174
* {@link LoggingReportScheduled}
166175
*
167176
* @param factoryBean logging factory bean
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright [2019] [恒宇少年 - 于起宇]
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
package org.minbox.framework.api.boot.autoconfigure.logging;
19+
20+
import org.minbox.framework.logging.client.LoggingFactoryBean;
21+
22+
/**
23+
* logging factory bean customizer
24+
* Initialization logging factory bean calls all implementation classes
25+
*
26+
* @author 恒宇少年
27+
*/
28+
public interface LoggingFactoryBeanCustomizer {
29+
/**
30+
* Customize the given a {@link LoggingFactoryBean} object.
31+
*
32+
* @param factoryBean the logging factory bean
33+
*/
34+
void customize(LoggingFactoryBean factoryBean);
35+
}

0 commit comments

Comments
 (0)