Skip to content

Commit f093c66

Browse files
committed
调整集成MinBox Logging自动化配置
1 parent 899e5aa commit f093c66

File tree

3 files changed

+103
-171
lines changed

3 files changed

+103
-171
lines changed

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

Lines changed: 53 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,14 @@
1717

1818
package org.minbox.framework.api.boot.autoconfigure.logging;
1919

20+
import org.minbox.framework.logging.client.LoggingFactoryBean;
2021
import org.minbox.framework.logging.client.admin.discovery.LoggingAdminDiscovery;
21-
import org.minbox.framework.logging.client.admin.report.LoggingAdminReport;
2222
import org.minbox.framework.logging.client.admin.report.LoggingReportScheduled;
23-
import org.minbox.framework.logging.client.admin.report.support.LoggingAdminReportSupport;
24-
import org.minbox.framework.logging.client.cache.LoggingCache;
25-
import org.minbox.framework.logging.client.cache.support.LoggingMemoryCache;
2623
import org.minbox.framework.logging.client.filter.LoggingBodyFilter;
2724
import org.minbox.framework.logging.client.interceptor.LoggingInterceptor;
28-
import org.minbox.framework.logging.client.notice.LoggingNotice;
2925
import org.minbox.framework.logging.client.notice.LoggingNoticeListener;
30-
import org.minbox.framework.logging.client.notice.away.LoggingStorageNotice;
31-
import org.minbox.framework.logging.client.notice.away.support.LoggingAdminStorageNotice;
32-
import org.minbox.framework.logging.client.notice.away.support.LoggingLocalStorageNotice;
33-
import org.minbox.framework.logging.client.span.LoggingSpan;
34-
import org.minbox.framework.logging.client.span.support.LoggingDefaultSpan;
35-
import org.minbox.framework.logging.client.tracer.LoggingTracer;
36-
import org.minbox.framework.logging.client.tracer.support.LoggingDefaultTracer;
26+
import org.minbox.framework.logging.client.notice.support.LoggingAdminNotice;
27+
import org.minbox.framework.logging.client.notice.support.LoggingLocalNotice;
3728
import org.springframework.beans.factory.ObjectProvider;
3829
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
3930
import org.springframework.boot.autoconfigure.condition.*;
@@ -42,15 +33,7 @@
4233
import org.springframework.context.annotation.Bean;
4334
import org.springframework.context.annotation.Configuration;
4435
import org.springframework.context.annotation.Import;
45-
import org.springframework.context.annotation.Primary;
46-
import org.springframework.core.env.ConfigurableEnvironment;
47-
import org.springframework.http.client.ClientHttpRequestInterceptor;
4836
import org.springframework.scheduling.annotation.EnableAsync;
49-
import org.springframework.web.client.RestTemplate;
50-
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
51-
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
52-
53-
import java.util.List;
5437

5538
import static org.minbox.framework.api.boot.autoconfigure.logging.ApiBootLoggingProperties.API_BOOT_LOGGING_PREFIX;
5639

@@ -75,58 +58,53 @@
7558
ApiBootLoggingAdminDiscoveryAutoConfiguration.class,
7659
ApiBootLoggingAdminAppointAutoConfiguration.class,
7760
ApiBootLoggingOpenfeignAutoConfiguration.class,
78-
ApiBootLoggingRestTemplateAutoConfiguration.class
61+
ApiBootLoggingWebAutoConfiguration.class
7962
})
80-
public class ApiBootLoggingAutoConfiguration implements WebMvcConfigurer {
63+
public class ApiBootLoggingAutoConfiguration {
8164
/**
8265
* ApiBoot Logging Properties
8366
*/
8467
private ApiBootLoggingProperties apiBootLoggingProperties;
85-
/**
86-
* Configurable Environment
87-
*/
88-
private ConfigurableEnvironment environment;
8968

90-
public ApiBootLoggingAutoConfiguration(ApiBootLoggingProperties apiBootLoggingProperties, ConfigurableEnvironment environment) {
69+
public ApiBootLoggingAutoConfiguration(ApiBootLoggingProperties apiBootLoggingProperties) {
9170
this.apiBootLoggingProperties = apiBootLoggingProperties;
92-
this.environment = environment;
93-
}
94-
95-
/**
96-
* ApiBoot Logging Tracer
97-
*
98-
* @return ApiBootLoggingTracer
99-
*/
100-
@Bean
101-
@ConditionalOnMissingBean
102-
public LoggingTracer apiBootLoggingTracer() {
103-
return new LoggingDefaultTracer();
10471
}
10572

10673
/**
107-
* ApiBoot Logging Span
74+
* logging factory bean
75+
* {@link LoggingFactoryBean}
10876
*
109-
* @return ApiBootLoggingSpan
77+
* @return LoggingFactoryBean
11078
*/
11179
@Bean
11280
@ConditionalOnMissingBean
113-
public LoggingSpan apiBootLoggingSpan() {
114-
return new LoggingDefaultSpan();
81+
public LoggingFactoryBean loggingFactoryBean(ObjectProvider<LoggingAdminDiscovery> loggingAdminDiscoveryObjectProvider) {
82+
LoggingFactoryBean factoryBean = new LoggingFactoryBean();
83+
factoryBean.setIgnorePaths(apiBootLoggingProperties.getIgnorePaths());
84+
factoryBean.setReportAway(apiBootLoggingProperties.getReportAway());
85+
factoryBean.setNumberOfRequestLog(apiBootLoggingProperties.getReportNumberOfRequestLog());
86+
factoryBean.setReportInitialDelaySecond(apiBootLoggingProperties.getReportInitialDelaySecond());
87+
factoryBean.setReportIntervalSecond(apiBootLoggingProperties.getReportIntervalSecond());
88+
factoryBean.setLoggingAdminDiscovery(loggingAdminDiscoveryObjectProvider.getIfAvailable());
89+
return factoryBean;
11590
}
11691

11792
/**
118-
* ApiBoot Logging Interceptor
93+
* logging request interceptor
94+
* {@link LoggingInterceptor}
11995
*
120-
* @return ApiBootLoggingInterceptor
96+
* @param factoryBean logging factory bean
97+
* @return LoggingInterceptor
12198
*/
12299
@Bean
123100
@ConditionalOnMissingBean
124-
public LoggingInterceptor apiBootLoggingInterceptor() {
125-
return new LoggingInterceptor(environment, apiBootLoggingTracer(), apiBootLoggingSpan(), apiBootLoggingProperties.getIgnorePaths());
101+
public LoggingInterceptor loggingInterceptor(LoggingFactoryBean factoryBean) {
102+
return new LoggingInterceptor(factoryBean);
126103
}
127104

128105
/**
129106
* Instance Transmit Request Body Filter
107+
* {@link LoggingBodyFilter}
130108
*
131109
* @return ApiBootLoggingBodyFilter
132110
*/
@@ -137,103 +115,61 @@ public LoggingBodyFilter apiBootLoggingFilter() {
137115
}
138116

139117
/**
140-
* ApiBoot Logging Console Notice Listener
118+
* logging notice listener
119+
* {@link LoggingNoticeListener}
141120
*
142-
* @param loggingStorageNotice ApiBoot Logging Notice Support Instance
143-
* @return ApiBootLoggingNoticeListener
144-
* @see org.minbox.framework.logging.client.notice.away.support.LoggingLocalStorageNotice
145-
* @see org.minbox.framework.logging.client.notice.away.support.LoggingAdminStorageNotice
146-
*/
147-
@Bean
148-
public LoggingNoticeListener apiBootLoggingNoticeListener(LoggingStorageNotice loggingStorageNotice) {
149-
return new LoggingNoticeListener(loggingStorageNotice, apiBootLoggingProperties.isFormatConsoleLogJson(), apiBootLoggingProperties.isShowConsoleLog());
150-
}
151-
152-
153-
/**
154-
* ApiBoot Logging Local Notice
155-
*
156-
* @return ApiBootLoggingLocalStorageNotice
157-
*/
158-
@Bean
159-
@ConditionalOnMissingBean(LoggingAdminDiscovery.class)
160-
public LoggingLocalStorageNotice apiBootLoggingLocalNotice(ObjectProvider<List<LoggingNotice>> localNoticeObjectProvider) {
161-
return new LoggingLocalStorageNotice(localNoticeObjectProvider.getIfAvailable());
162-
}
163-
164-
/**
165-
* ApiBoot Logging Admin Notice
166-
*
167-
* @return ApiBootLoggingAdminStorageNotice
121+
* @return LoggingNoticeListener
168122
*/
169123
@Bean
170124
@ConditionalOnMissingBean
171-
@ConditionalOnBean(LoggingAdminDiscovery.class)
172-
public LoggingAdminStorageNotice apiBootLoggingAdminStorageNotice(LoggingCache loggingCache, LoggingAdminReport loggingAdminReport) {
173-
return new LoggingAdminStorageNotice(loggingCache, apiBootLoggingProperties.getReportAway(), loggingAdminReport);
125+
public LoggingNoticeListener loggingNoticeListener() {
126+
return new LoggingNoticeListener();
174127
}
175128

176129
/**
177-
* Logging Memory Cache
130+
* logging local notice
131+
* {@link LoggingLocalNotice}
178132
*
179-
* @return LoggingMemoryCache
133+
* @return LoggingLocalNotice
180134
*/
181135
@Bean
182-
@ConditionalOnProperty(prefix = API_BOOT_LOGGING_PREFIX, name = "logging-cache-away", havingValue = "memory", matchIfMissing = true)
183136
@ConditionalOnMissingBean
184-
public LoggingCache loggingMemoryCache() {
185-
return new LoggingMemoryCache();
137+
public LoggingLocalNotice loggingLocalNotice() {
138+
LoggingLocalNotice localNotice = new LoggingLocalNotice();
139+
localNotice.setShowConsoleLog(apiBootLoggingProperties.isShowConsoleLog());
140+
localNotice.setFormatConsoleLogJson(apiBootLoggingProperties.isFormatConsoleLogJson());
141+
return localNotice;
186142
}
187143

188144
/**
189-
* Logging Admin Report
145+
* logging admin notice
146+
* report request logging to admins
147+
* {@link LoggingAdminNotice}
148+
* {@link LoggingAdminDiscovery}
190149
*
191-
* @param loggingAdminDiscovery Logging Admin Discovery
192-
* @param restTemplate RestTemplate
193-
* @param loggingCache Logging Cache
194-
* @return LoggingAdminReportSupport
150+
* @param factoryBean logging factory bean
151+
* @return LoggingAdminNotice
195152
*/
196153
@Bean
197154
@ConditionalOnBean(LoggingAdminDiscovery.class)
198-
@ConditionalOnMissingBean
199-
public LoggingAdminReport loggingAdminReportSupport(LoggingAdminDiscovery loggingAdminDiscovery, RestTemplate restTemplate, LoggingCache loggingCache, ConfigurableEnvironment environment) {
200-
return new LoggingAdminReportSupport(loggingAdminDiscovery, restTemplate, loggingCache, apiBootLoggingProperties.getReportNumberOfRequestLog(), environment);
155+
public LoggingAdminNotice loggingAdminNotice(LoggingFactoryBean factoryBean) {
156+
return new LoggingAdminNotice(factoryBean);
201157
}
202158

203159
/**
204160
* Logging Report Scheduled Task Job
161+
* When the configuration parameter "api.boot.logging.report-away=timing" is configured,
162+
* the creation timing task is performed to report log information to admin node
163+
* {@link ApiBootLoggingProperties#getReportAway()}
164+
* {@link LoggingReportScheduled}
205165
*
206-
* @param loggingAdminReport Logging Admin Report
166+
* @param factoryBean logging factory bean
207167
* @return LoggingReportScheduled
208168
*/
209169
@Bean
210170
@ConditionalOnProperty(prefix = API_BOOT_LOGGING_PREFIX, name = "report-away", havingValue = "timing")
211171
@ConditionalOnMissingBean
212-
public LoggingReportScheduled loggingReportScheduled(LoggingAdminReport loggingAdminReport) {
213-
return new LoggingReportScheduled(loggingAdminReport, apiBootLoggingProperties.getReportInitialDelaySecond(), apiBootLoggingProperties.getReportIntervalSecond());
214-
}
215-
216-
/**
217-
* registry logging interceptor
218-
*
219-
* @param registry registry interceptor
220-
*/
221-
@Override
222-
public void addInterceptors(InterceptorRegistry registry) {
223-
registry.addInterceptor(apiBootLoggingInterceptor()).addPathPatterns(apiBootLoggingProperties.getLoggingPathPrefix());
224-
}
225-
226-
/**
227-
* Rest Template Instance
228-
*
229-
* @return RestTemplate
230-
*/
231-
@Bean
232-
@Primary
233-
@ConditionalOnMissingBean
234-
public RestTemplate restTemplate(ObjectProvider<List<ClientHttpRequestInterceptor>> interceptorObjectProvider) {
235-
RestTemplate restTemplate = new RestTemplate();
236-
restTemplate.setInterceptors(interceptorObjectProvider.getIfAvailable());
237-
return restTemplate;
172+
public LoggingReportScheduled loggingReportScheduled(LoggingFactoryBean factoryBean) {
173+
return new LoggingReportScheduled(factoryBean);
238174
}
239175
}

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

Lines changed: 0 additions & 54 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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.interceptor.LoggingInterceptor;
21+
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
22+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
23+
import org.springframework.context.annotation.Configuration;
24+
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
25+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
26+
27+
/**
28+
* ApiBoot logging web auto configuration
29+
* registry MinBox logging request interceptor
30+
* {@link LoggingInterceptor}
31+
*
32+
* @author 恒宇少年
33+
*/
34+
@Configuration
35+
@EnableConfigurationProperties(ApiBootLoggingProperties.class)
36+
@AutoConfigureAfter(ApiBootLoggingAutoConfiguration.class)
37+
public class ApiBootLoggingWebAutoConfiguration implements WebMvcConfigurer {
38+
private LoggingInterceptor loggingInterceptor;
39+
private ApiBootLoggingProperties loggingProperties;
40+
41+
public ApiBootLoggingWebAutoConfiguration(LoggingInterceptor loggingInterceptor, ApiBootLoggingProperties loggingProperties) {
42+
this.loggingInterceptor = loggingInterceptor;
43+
this.loggingProperties = loggingProperties;
44+
}
45+
46+
@Override
47+
public void addInterceptors(InterceptorRegistry registry) {
48+
registry.addInterceptor(loggingInterceptor).addPathPatterns(loggingProperties.getLoggingPathPrefix());
49+
}
50+
}

0 commit comments

Comments
 (0)