SGTY 4 miesięcy temu
rodzic
commit
a80f155128

+ 5 - 0
kernel/pom.xml

@@ -25,6 +25,11 @@
     </properties>
 
     <dependencies>
+        <dependency>
+            <groupId>com.diagbot</groupId>
+            <artifactId>common</artifactId>
+            <version>0.0.1.1-SNAPSHOT</version>
+        </dependency>
         <dependency>
             <groupId>com.lantone.qc</groupId>
             <artifactId>security</artifactId>

+ 2 - 0
kernel/src/main/java/com/lantone/qc/kernel/KernelApplication.java

@@ -1,5 +1,6 @@
 package com.lantone.qc.kernel;
 
+import com.diagbot.annotation.EnableMonitor;
 import com.lantone.qc.kernel.web.config.CustomNameGenerator;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -9,6 +10,7 @@ import org.springframework.context.annotation.ComponentScan;
 
 @EnableFeignClients
 @SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
+@EnableMonitor(pointcut="execution(public * com.lantone.qc.kernel..*(..)) && !execution(public * com.lantone.qc.kernel..config..*(..))")
 @ComponentScan(nameGenerator = CustomNameGenerator.class, value = {
         "com.lantone.qc.dbanaly",
         "com.lantone.qc.nlp",

+ 41 - 0
kernel/src/main/java/com/lantone/qc/kernel/web/config/MonitorAutoConfiguration.java

@@ -0,0 +1,41 @@
+package com.lantone.qc.kernel.web.config;
+
+
+import com.diagbot.annotation.EnableMonitor;
+import com.diagbot.aop.InterfaceLogAspect;
+import com.diagbot.interceptor.CustomInterceptor;
+import com.diagbot.interceptor.FeignRequestInterceptor;
+import feign.RequestInterceptor;
+import feign.RequestTemplate;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Lazy;
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+@Configuration
+@ConditionalOnBean(annotation = { EnableMonitor.class})
+public class MonitorAutoConfiguration implements WebMvcConfigurer {
+
+    @Override
+    public void addInterceptors(InterceptorRegistry registry) {
+        registry.addInterceptor(new CustomInterceptor())
+                .addPathPatterns("/**").excludePathPatterns("/static/**", "/css/**", "/js/**"); // 排除静态资源
+    }
+
+    @Bean
+    @Lazy
+    public InterfaceLogAspect interfaceLogAspect() {
+        return new InterfaceLogAspect();
+    }
+
+    @Bean
+    @Lazy
+    @ConditionalOnClass({
+        RequestInterceptor.class, RequestTemplate.class})
+    public FeignRequestInterceptor feignRequestInterceptor() {
+        return new FeignRequestInterceptor();
+    }
+}

+ 2 - 2
kernel/src/main/resources/logback-spring.xml

@@ -17,7 +17,7 @@
     <conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" />
     <conversionRule conversionWord="wEx" converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter" />
     <!-- 彩色日志格式 -->
-    <property name="CONSOLE_LOG_PATTERN" value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/>
+    <property name="CONSOLE_LOG_PATTERN" value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- } %X{Trace-Id}){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/>
 
 
     <!--输出到控制台-->
@@ -80,7 +80,7 @@
                 <maxFileSize>100MB</maxFileSize>
             </timeBasedFileNamingAndTriggeringPolicy>
             <!--日志文件保留天数-->
-            <maxHistory>15</maxHistory>
+            <maxHistory>1</maxHistory>
         </rollingPolicy>
         <!-- 此日志文件只记录info级别的 -->
         <filter class="ch.qos.logback.classic.filter.LevelFilter">