Skip to content

Commit 1b9eece

Browse files
committed
添加ApiBoot Logging 自动化配置
1 parent d5541bf commit 1b9eece

File tree

6 files changed

+300
-1
lines changed

6 files changed

+300
-1
lines changed

api-boot-project/api-boot-autoconfigure/pom.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,5 +201,19 @@
201201
<optional>true</optional>
202202
</dependency>
203203

204+
<!--ApiBoot Logging-->
205+
<dependency>
206+
<groupId>org.minbox.framework</groupId>
207+
<artifactId>api-boot-plugin-logging</artifactId>
208+
<optional>true</optional>
209+
</dependency>
210+
211+
<!--SpringCloud Openfeign-->
212+
<dependency>
213+
<groupId>org.springframework.cloud</groupId>
214+
<artifactId>spring-cloud-starter-openfeign</artifactId>
215+
<optional>true</optional>
216+
</dependency>
217+
204218
</dependencies>
205219
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
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.api.boot.plugin.logging.ApiBootLog;
21+
import org.minbox.framework.api.boot.plugin.logging.filter.ApiBootLoggingBodyFilter;
22+
import org.minbox.framework.api.boot.plugin.logging.interceptor.ApiBootLoggingInterceptor;
23+
import org.minbox.framework.api.boot.plugin.logging.notice.away.ApiBootLogStorageNotice;
24+
import org.minbox.framework.api.boot.plugin.logging.notice.ApiBootLoggingNoticeListener;
25+
import org.minbox.framework.api.boot.plugin.logging.notice.ApiBootLogNotice;
26+
import org.minbox.framework.api.boot.plugin.logging.notice.away.support.ApiBootLoggingLocalStorageNotice;
27+
import org.minbox.framework.api.boot.plugin.logging.span.ApiBootLoggingSpan;
28+
import org.minbox.framework.api.boot.plugin.logging.span.support.ApiBootLoggingDefaultSpan;
29+
import org.minbox.framework.api.boot.plugin.logging.tracer.ApiBootLoggingTracer;
30+
import org.minbox.framework.api.boot.plugin.logging.tracer.support.ApiBootLoggingDefaultTracer;
31+
import org.springframework.beans.factory.ObjectProvider;
32+
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
33+
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
34+
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
35+
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
36+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
37+
import org.springframework.context.annotation.Bean;
38+
import org.springframework.context.annotation.Configuration;
39+
import org.springframework.core.env.ConfigurableEnvironment;
40+
import org.springframework.web.servlet.HandlerInterceptor;
41+
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
42+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
43+
44+
import java.util.List;
45+
46+
/**
47+
* ApiBoot Logging Auto Configuration
48+
*
49+
* @author:恒宇少年 - 于起宇
50+
* <p>
51+
* DateTime:2019-07-15 18:33
52+
* Blog:http://blog.yuqiyu.com
53+
* WebSite:http://www.jianshu.com/u/092df3f77bca
54+
* Gitee:https://gitee.com/hengboy
55+
* GitHub:https://github.com/hengboy
56+
*/
57+
@Configuration
58+
@ConditionalOnClass({ApiBootLog.class, HandlerInterceptor.class})
59+
@EnableConfigurationProperties(ApiBootLoggingProperties.class)
60+
@AutoConfigureAfter(WebMvcAutoConfiguration.class)
61+
public class ApiBootLoggingAutoConfiguration implements WebMvcConfigurer {
62+
/**
63+
* ApiBoot Logging Properties
64+
*/
65+
private ApiBootLoggingProperties apiBootLoggingProperties;
66+
/**
67+
* Configurable Environment
68+
*/
69+
private ConfigurableEnvironment environment;
70+
71+
public ApiBootLoggingAutoConfiguration(ApiBootLoggingProperties apiBootLoggingProperties, ConfigurableEnvironment environment) {
72+
this.apiBootLoggingProperties = apiBootLoggingProperties;
73+
this.environment = environment;
74+
}
75+
76+
/**
77+
* ApiBoot Logging Tracer
78+
*
79+
* @return ApiBootLoggingTracer
80+
*/
81+
@Bean
82+
@ConditionalOnMissingBean
83+
public ApiBootLoggingTracer apiBootLoggingTracer() {
84+
return new ApiBootLoggingDefaultTracer();
85+
}
86+
87+
/**
88+
* ApiBoot Logging Span
89+
*
90+
* @return ApiBootLoggingSpan
91+
*/
92+
@Bean
93+
@ConditionalOnMissingBean
94+
public ApiBootLoggingSpan apiBootLoggingSpan() {
95+
return new ApiBootLoggingDefaultSpan();
96+
}
97+
98+
/**
99+
* ApiBoot Logging Interceptor
100+
*
101+
* @return ApiBootLoggingInterceptor
102+
*/
103+
@Bean
104+
@ConditionalOnMissingBean
105+
public ApiBootLoggingInterceptor apiBootLoggingInterceptor() {
106+
return new ApiBootLoggingInterceptor(environment, apiBootLoggingTracer(), apiBootLoggingSpan(), apiBootLoggingProperties.getIgnorePaths());
107+
}
108+
109+
/**
110+
* Instance Transmit Request Body Filter
111+
*
112+
* @return ApiBootLoggingBodyFilter
113+
*/
114+
@Bean
115+
@ConditionalOnMissingBean
116+
public ApiBootLoggingBodyFilter apiBootLoggingFilter() {
117+
return new ApiBootLoggingBodyFilter();
118+
}
119+
120+
/**
121+
* ApiBoot Logging Local Notice
122+
*
123+
* @return ApiBootLoggingLocalStorageNotice
124+
*/
125+
@Bean
126+
@ConditionalOnMissingBean
127+
public ApiBootLoggingLocalStorageNotice apiBootLoggingLocalNotice(ObjectProvider<List<ApiBootLogNotice>> localNoticeObjectProvider) {
128+
return new ApiBootLoggingLocalStorageNotice(localNoticeObjectProvider.getIfAvailable());
129+
}
130+
131+
/**
132+
* ApiBoot Logging Console Notice Listener
133+
*
134+
* @param apiBootLogStorageNotice ApiBoot Logging Notice Support Instance
135+
* @return ApiBootLoggingNoticeListener
136+
* @see ApiBootLoggingLocalStorageNotice
137+
* @see org.minbox.framework.api.boot.plugin.logging.notice.away.support.ApiBootLoggingRestStorageNotice
138+
* @see org.minbox.framework.api.boot.plugin.logging.notice.away.support.ApiBootLoggingMqStorageNotice
139+
*/
140+
@Bean
141+
public ApiBootLoggingNoticeListener apiBootLoggingNoticeListener(ApiBootLogStorageNotice apiBootLogStorageNotice) {
142+
return new ApiBootLoggingNoticeListener(apiBootLogStorageNotice);
143+
}
144+
145+
146+
/**
147+
* registry logging interceptor
148+
*
149+
* @param registry registry interceptor
150+
*/
151+
@Override
152+
public void addInterceptors(InterceptorRegistry registry) {
153+
registry.addInterceptor(apiBootLoggingInterceptor()).addPathPatterns(apiBootLoggingProperties.getLoggingPathPrefix());
154+
}
155+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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 feign.RequestInterceptor;
21+
import org.minbox.framework.api.boot.plugin.logging.http.openfeign.ApiBootLogOpenFeignInterceptor;
22+
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
23+
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
24+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
25+
import org.springframework.context.annotation.Bean;
26+
import org.springframework.context.annotation.Configuration;
27+
28+
/**
29+
* ApiBoot Logging Openfeign Http Away Configuration
30+
*
31+
* @author:恒宇少年 - 于起宇
32+
* <p>
33+
* DateTime:2019-07-16 16:05
34+
* Blog:http://blog.yuqiyu.com
35+
* WebSite:http://www.jianshu.com/u/092df3f77bca
36+
* Gitee:https://gitee.com/hengboy
37+
* GitHub:https://github.com/hengboy
38+
*/
39+
@Configuration
40+
@ConditionalOnClass(RequestInterceptor.class)
41+
@EnableConfigurationProperties(ApiBootLoggingProperties.class)
42+
public class ApiBootLoggingOpenfeignAutoConfiguration {
43+
44+
/**
45+
* ApiBoot Logging Openfeign Interceptor
46+
*
47+
* @return ApiBootLogOpenFeignInterceptor
48+
*/
49+
@Bean
50+
@ConditionalOnMissingBean
51+
public ApiBootLogOpenFeignInterceptor apiBootLogOpenFeignInterceptor() {
52+
return new ApiBootLogOpenFeignInterceptor();
53+
}
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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 lombok.Data;
21+
import lombok.Getter;
22+
import org.springframework.boot.context.properties.ConfigurationProperties;
23+
import org.springframework.context.annotation.Configuration;
24+
25+
import static org.minbox.framework.api.boot.autoconfigure.logging.ApiBootLoggingProperties.API_BOOT_LOGGING_PREFIX;
26+
27+
/**
28+
* ApiBoot Logging Properties
29+
*
30+
* @author:恒宇少年 - 于起宇
31+
* <p>
32+
* DateTime:2019-07-15 22:29
33+
* Blog:http://blog.yuqiyu.com
34+
* WebSite:http://www.jianshu.com/u/092df3f77bca
35+
* Gitee:https://gitee.com/hengboy
36+
* GitHub:https://github.com/hengboy
37+
*/
38+
@Configuration
39+
@ConfigurationProperties(prefix = API_BOOT_LOGGING_PREFIX)
40+
@Data
41+
public class ApiBootLoggingProperties {
42+
/**
43+
* ApiBoot logging properties config prefix
44+
*/
45+
public static final String API_BOOT_LOGGING_PREFIX = "api.boot.logging";
46+
/**
47+
* Interception log path prefix
48+
*/
49+
private String[] loggingPathPrefix = new String[]{"/**"};
50+
/**
51+
* Ignore path array
52+
*/
53+
private String[] ignorePaths;
54+
}

api-boot-project/api-boot-autoconfigure/src/main/resources/META-INF/spring.factories

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
1616
org.minbox.framework.api.boot.autoconfigure.pageable.ApiBootMybatisPageableAutoConfiguration,\
1717
org.minbox.framework.api.boot.autoconfigure.enhance.ApiBootMyBatisEnhanceAutoConfiguration,\
1818
org.minbox.framework.api.boot.autoconfigure.ratelimiter.ApiBootRateLimiterAutoConfiguration,\
19-
org.minbox.framework.api.boot.autoconfigure.mail.ApiBootMailAutoConfiguration
19+
org.minbox.framework.api.boot.autoconfigure.mail.ApiBootMailAutoConfiguration,\
20+
org.minbox.framework.api.boot.autoconfigure.logging.ApiBootLoggingAutoConfiguration,\
21+
org.minbox.framework.api.boot.autoconfigure.logging.ApiBootLoggingOpenfeignAutoConfiguration

api-boot-project/api-boot-dependencies/pom.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<properties>
1616
<main.basedir>${basedir}/../..</main.basedir>
1717
<spring.boot.version>2.1.6.RELEASE</spring.boot.version>
18+
<spring.cloud.version>Greenwich.RELEASE</spring.cloud.version>
1819
<api.boot.version>2.1.1-SNAPSHOT</api.boot.version>
1920
<druid.version>1.1.17</druid.version>
2021
<druid.starter.version>1.1.17</druid.starter.version>
@@ -59,6 +60,13 @@
5960
<type>pom</type>
6061
<scope>import</scope>
6162
</dependency>
63+
<dependency>
64+
<groupId>org.springframework.cloud</groupId>
65+
<artifactId>spring-cloud-dependencies</artifactId>
66+
<version>${spring.cloud.version}</version>
67+
<type>pom</type>
68+
<scope>import</scope>
69+
</dependency>
6270

6371
<!--ApiBoot Starter-->
6472
<dependency>
@@ -375,6 +383,18 @@
375383
<version>${aliyun-java-sdk-dm.version}</version>
376384
</dependency>
377385

386+
<!--ApiBoot Logging-->
387+
<dependency>
388+
<groupId>org.minbox.framework</groupId>
389+
<artifactId>api-boot-plugin-logging</artifactId>
390+
<version>${api.boot.version}</version>
391+
</dependency>
392+
<dependency>
393+
<groupId>org.minbox.framework</groupId>
394+
<artifactId>api-boot-starter-logging</artifactId>
395+
<version>${api.boot.version}</version>
396+
</dependency>
397+
378398
</dependencies>
379399
</dependencyManagement>
380400

0 commit comments

Comments
 (0)