|
| 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 | +} |
0 commit comments