Skip to content

Commit 2b174c8

Browse files
committed
ApiBoot Logging Admin 自动化配置
1 parent 3725772 commit 2b174c8

File tree

4 files changed

+180
-1
lines changed

4 files changed

+180
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
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.admin;
19+
20+
import org.minbox.framework.api.boot.plugin.logging.admin.discovery.LoggingAdminDiscovery;
21+
import org.minbox.framework.api.boot.plugin.logging.admin.endpoint.LoggingEndpoint;
22+
import org.minbox.framework.api.boot.plugin.logging.admin.endpoint.LoggingRequestMappingHandlerMapping;
23+
import org.minbox.framework.api.boot.plugin.logging.admin.listener.ReportLogJsonFormatListener;
24+
import org.minbox.framework.api.boot.plugin.logging.admin.listener.ReportLogStorageListener;
25+
import org.minbox.framework.api.boot.plugin.logging.admin.storage.LoggingDataSourceStorage;
26+
import org.minbox.framework.api.boot.plugin.logging.admin.storage.LoggingStorage;
27+
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
28+
import org.springframework.boot.autoconfigure.condition.*;
29+
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
30+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
31+
import org.springframework.context.annotation.Bean;
32+
import org.springframework.context.annotation.Configuration;
33+
import org.springframework.web.servlet.HandlerMapping;
34+
35+
import javax.sql.DataSource;
36+
37+
/**
38+
* ApiBoot Logging Admin Configuration
39+
*
40+
* @author:恒宇少年 - 于起宇
41+
* <p>
42+
* DateTime:2019-07-19 10:38
43+
* Blog:http://blog.yuqiyu.com
44+
* WebSite:http://www.jianshu.com/u/092df3f77bca
45+
* Gitee:https://gitee.com/hengboy
46+
* GitHub:https://github.com/hengboy
47+
*/
48+
@Configuration
49+
@ConditionalOnClass(LoggingEndpoint.class)
50+
@ConditionalOnWebApplication
51+
@EnableConfigurationProperties(ApiBootLoggingAdminProperties.class)
52+
@AutoConfigureAfter(DataSourceAutoConfiguration.class)
53+
public class ApiBootLoggingAdminAutoConfiguration {
54+
/**
55+
* ApiBoot Logging Admin Properties
56+
*/
57+
private ApiBootLoggingAdminProperties apiBootLoggingAdminProperties;
58+
59+
public ApiBootLoggingAdminAutoConfiguration(ApiBootLoggingAdminProperties apiBootLoggingAdminProperties) {
60+
this.apiBootLoggingAdminProperties = apiBootLoggingAdminProperties;
61+
}
62+
63+
/**
64+
* ApiBoot Logging Endpoint
65+
* Receive Log report
66+
*
67+
* @return LoggingEndpoint
68+
*/
69+
@Bean
70+
@ConditionalOnMissingBean
71+
public LoggingEndpoint loggingEndpoint() {
72+
return new LoggingEndpoint();
73+
}
74+
75+
/**
76+
* ApiBoot Logging Request Mapping
77+
*
78+
* @return HandlerMapping
79+
*/
80+
@Bean
81+
public HandlerMapping loggingRequestMappingHandlerMapping() {
82+
return new LoggingRequestMappingHandlerMapping(loggingEndpoint());
83+
}
84+
85+
/**
86+
* Report Log Json Format Listener
87+
*
88+
* @return ReportLogJsonFormatListener
89+
*/
90+
@Bean
91+
@ConditionalOnMissingBean
92+
public ReportLogJsonFormatListener reportLogJsonFormatListener() {
93+
return new ReportLogJsonFormatListener(apiBootLoggingAdminProperties.isShowConsoleReportLog(), apiBootLoggingAdminProperties.isFormatConsoleLogJson());
94+
}
95+
96+
/**
97+
* Storage Request Log Configuration
98+
*/
99+
@Configuration
100+
@ConditionalOnBean(DataSource.class)
101+
public static class StorageLogAutoConfiguration {
102+
/**
103+
* Logging DataSource Storage
104+
*
105+
* @return LoggingDataSourceStorage
106+
*/
107+
@Bean
108+
@ConditionalOnMissingBean
109+
public LoggingStorage loggingStorage(DataSource dataSource) {
110+
return new LoggingDataSourceStorage(dataSource);
111+
}
112+
113+
/**
114+
* Report Log Storage Listener
115+
*
116+
* @return ReportLogStorageListener
117+
*/
118+
@Bean
119+
@ConditionalOnMissingBean
120+
public ReportLogStorageListener reportLogStorageListener(LoggingStorage loggingStorage) {
121+
return new ReportLogStorageListener(loggingStorage);
122+
}
123+
}
124+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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.admin;
19+
20+
import lombok.Data;
21+
import org.springframework.boot.context.properties.ConfigurationProperties;
22+
import org.springframework.context.annotation.Configuration;
23+
24+
import static org.minbox.framework.api.boot.autoconfigure.logging.admin.ApiBootLoggingAdminProperties.API_BOOT_LOGGING_ADMIN_PREFIX;
25+
26+
/**
27+
* ApiBoot Logging Admin Properties
28+
*
29+
* @author:恒宇少年 - 于起宇
30+
* <p>
31+
* DateTime:2019-07-19 12:56
32+
* Blog:http://blog.yuqiyu.com
33+
* WebSite:http://www.jianshu.com/u/092df3f77bca
34+
* Gitee:https://gitee.com/hengboy
35+
* GitHub:https://github.com/hengboy
36+
*/
37+
@Configuration
38+
@ConfigurationProperties(prefix = API_BOOT_LOGGING_ADMIN_PREFIX)
39+
@Data
40+
public class ApiBootLoggingAdminProperties {
41+
/**
42+
* ApiBoot logging properties config prefix
43+
*/
44+
public static final String API_BOOT_LOGGING_ADMIN_PREFIX = "api.boot.logging.admin";
45+
/**
46+
* Whether to print the logs reported on the console
47+
*/
48+
private boolean showConsoleReportLog = false;
49+
/**
50+
* Format console log JSON
51+
*/
52+
private boolean formatConsoleLogJson = false;
53+
}

api-boot-project/api-boot-autoconfigure/src/main/java/org/minbox/framework/api/boot/autoconfigure/security/ApiBootWebSecurityAutoConfiguration.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.minbox.framework.api.boot.plugin.security.ApiBootWebSecurityConfiguration;
2020
import org.minbox.framework.api.boot.plugin.security.point.ApiBootDefaultAuthenticationEntryPoint;
2121
import org.minbox.framework.api.boot.plugin.security.handler.ApiBootDefaultAccessDeniedHandler;
22+
import org.springframework.core.annotation.Order;
2223
import org.springframework.security.web.AuthenticationEntryPoint;
2324
import org.springframework.security.web.access.AccessDeniedHandler;
2425
import org.springframework.util.ObjectUtils;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
1818
org.minbox.framework.api.boot.autoconfigure.ratelimiter.ApiBootRateLimiterAutoConfiguration,\
1919
org.minbox.framework.api.boot.autoconfigure.mail.ApiBootMailAutoConfiguration,\
2020
org.minbox.framework.api.boot.autoconfigure.logging.ApiBootLoggingAutoConfiguration,\
21-
org.minbox.framework.api.boot.autoconfigure.logging.ApiBootLoggingOpenfeignAutoConfiguration
21+
org.minbox.framework.api.boot.autoconfigure.logging.ApiBootLoggingOpenfeignAutoConfiguration,\
22+
org.minbox.framework.api.boot.autoconfigure.logging.admin.ApiBootLoggingAdminAutoConfiguration

0 commit comments

Comments
 (0)