From d79d4816faa48a45790d2060618fdee62dd16007 Mon Sep 17 00:00:00 2001 From: huangfeng Date: Mon, 15 Jan 2024 10:31:14 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=B0=83=E6=95=B4=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=EF=BC=8C=E5=A2=9E=E5=8A=A0=E6=AF=8F=E4=B8=AA?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E8=B0=83=E7=94=A8=E7=9A=84=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xydl/cac/config/InterceptorConfig.java | 17 +++++++ .../cac/interceptor/GateWayInterceptor.java | 25 +++++++++ src/main/resources/application-dev.yml | 16 +----- src/main/resources/application-prod.yml | 15 +----- src/main/resources/logback.xml | 51 +++++++++++++++++++ 5 files changed, 95 insertions(+), 29 deletions(-) create mode 100644 src/main/java/com/xydl/cac/config/InterceptorConfig.java create mode 100644 src/main/java/com/xydl/cac/interceptor/GateWayInterceptor.java create mode 100644 src/main/resources/logback.xml diff --git a/src/main/java/com/xydl/cac/config/InterceptorConfig.java b/src/main/java/com/xydl/cac/config/InterceptorConfig.java new file mode 100644 index 0000000..46e29b6 --- /dev/null +++ b/src/main/java/com/xydl/cac/config/InterceptorConfig.java @@ -0,0 +1,17 @@ +package com.xydl.cac.config; + +import com.xydl.cac.interceptor.GateWayInterceptor; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@Configuration +public class InterceptorConfig implements WebMvcConfigurer { + /** + * 注册自定义拦截器 + */ + @Override + public void addInterceptors(InterceptorRegistry registry) { + registry.addInterceptor(new GateWayInterceptor()).addPathPatterns("/**"); + } +} diff --git a/src/main/java/com/xydl/cac/interceptor/GateWayInterceptor.java b/src/main/java/com/xydl/cac/interceptor/GateWayInterceptor.java new file mode 100644 index 0000000..3d7d25b --- /dev/null +++ b/src/main/java/com/xydl/cac/interceptor/GateWayInterceptor.java @@ -0,0 +1,25 @@ +package com.xydl.cac.interceptor; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.Enumeration; + +@Slf4j +public class GateWayInterceptor extends HandlerInterceptorAdapter { + + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { + StringBuilder str = new StringBuilder(request.getRequestURI() + " called"); + Enumeration params = request.getParameterNames(); + while (params.hasMoreElements()) { + String paramName = params.nextElement(); + str.append(", ").append(paramName).append("=").append(request.getParameter(paramName)); + } + log.info(str.toString()); + return super.preHandle(request, response, handler); + } + +} diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index f414ca4..9168668 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -13,7 +13,7 @@ spring: username: root password: 123456 jpa: - show-sql: true + show-sql: false open-in-view: false mvc: format: @@ -24,17 +24,3 @@ spring: multipart: max-file-size: 100MB max-request-size: 100MB - -logging: - level: - root: info - com: - xydl: debug - file: - name: /home/xydl/ncac/logs/ncac.log - - - - - - diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index 7ab9bf0..7053936 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -13,7 +13,7 @@ spring: username: iec password: Iec@1043 jpa: - show-sql: true + show-sql: false open-in-view: false mvc: format: @@ -24,16 +24,3 @@ spring: multipart: max-file-size: 100MB max-request-size: 100MB - -logging: - level: - root: info - com: - xydl: debug - file: - name: /home/xydl/ncac/logs/ncac.log - - - - - diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml new file mode 100644 index 0000000..376a6dc --- /dev/null +++ b/src/main/resources/logback.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %c:%L-->%m%n + + + + + + %d{HH:mm:ss.SSS} %-5level %logger{36} [%line] - %msg%n + + + logs/ncac.%d{yyyy-MM-dd}.log + + 60 + + + + + + + + + + + + + + + + + + + \ No newline at end of file