1717
1818package org .minbox .framework .api .boot .autoconfigure .logging ;
1919
20+ import org .minbox .framework .logging .client .LoggingFactoryBean ;
2021import org .minbox .framework .logging .client .admin .discovery .LoggingAdminDiscovery ;
21- import org .minbox .framework .logging .client .admin .report .LoggingAdminReport ;
2222import 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 ;
2623import org .minbox .framework .logging .client .filter .LoggingBodyFilter ;
2724import org .minbox .framework .logging .client .interceptor .LoggingInterceptor ;
28- import org .minbox .framework .logging .client .notice .LoggingNotice ;
2925import 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 ;
3728import org .springframework .beans .factory .ObjectProvider ;
3829import org .springframework .boot .autoconfigure .AutoConfigureAfter ;
3930import org .springframework .boot .autoconfigure .condition .*;
4233import org .springframework .context .annotation .Bean ;
4334import org .springframework .context .annotation .Configuration ;
4435import 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 ;
4836import 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
5538import static org .minbox .framework .api .boot .autoconfigure .logging .ApiBootLoggingProperties .API_BOOT_LOGGING_PREFIX ;
5639
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}
0 commit comments