From c32dc69827d9d10880234e72ec643ae047f6cf68 Mon Sep 17 00:00:00 2001 From: Charles7c Date: Wed, 11 Dec 2024 08:50:24 +0000 Subject: [PATCH] =?UTF-8?q?!35=20=E5=9B=9E=E9=80=80=20'Pull=20Request=20!3?= =?UTF-8?q?4=20:=20=E6=96=B0=E5=A2=9E=20log-aop=20=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E6=A8=A1=E5=9D=97'=20*=20=E5=9B=9E=E9=80=80=20'Pull=20Request?= =?UTF-8?q?=20!34=20:=20=E6=96=B0=E5=A2=9E=20log-aop=20=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E6=A8=A1=E5=9D=97'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- continew-starter-dependencies/pom.xml | 10 +- .../continew-starter-log-aop/pom.xml | 21 -- .../annotation/ConditionalOnEnabledLog.java | 35 --- .../starter/log/aop/annotation/Log.java | 54 ----- .../log/aop/aspect/ConsoleLogAspect.java | 80 ------- .../starter/log/aop/aspect/LogAspect.java | 221 ------------------ .../autoconfigure/LogAutoConfiguration.java | 87 ------- .../log/aop/autoconfigure/LogProperties.java | 76 ------ ...ot.autoconfigure.AutoConfiguration.imports | 1 - .../starter/log/core}/annotation/Log.java | 2 +- .../starter/log/core/model/LogRecord.java | 14 -- .../starter/log/core/model/LogRequest.java | 1 - .../starter/log/core/model/LogResponse.java | 1 - .../RecordableHttpRequest.java | 2 +- .../RecordableHttpResponse.java | 2 +- .../ConditionalOnEnabledLog.java | 2 +- .../autoconfigure/LogAutoConfiguration.java | 3 +- .../interceptor/handler/LogInterceptor.java | 4 +- .../RecordableServletHttpRequest.java | 4 +- .../RecordableServletHttpResponse.java | 4 +- continew-starter-log/pom.xml | 1 - 21 files changed, 11 insertions(+), 614 deletions(-) delete mode 100644 continew-starter-log/continew-starter-log-aop/pom.xml delete mode 100644 continew-starter-log/continew-starter-log-aop/src/main/java/top/continew/starter/log/aop/annotation/ConditionalOnEnabledLog.java delete mode 100644 continew-starter-log/continew-starter-log-aop/src/main/java/top/continew/starter/log/aop/annotation/Log.java delete mode 100644 continew-starter-log/continew-starter-log-aop/src/main/java/top/continew/starter/log/aop/aspect/ConsoleLogAspect.java delete mode 100644 continew-starter-log/continew-starter-log-aop/src/main/java/top/continew/starter/log/aop/aspect/LogAspect.java delete mode 100644 continew-starter-log/continew-starter-log-aop/src/main/java/top/continew/starter/log/aop/autoconfigure/LogAutoConfiguration.java delete mode 100644 continew-starter-log/continew-starter-log-aop/src/main/java/top/continew/starter/log/aop/autoconfigure/LogProperties.java delete mode 100644 continew-starter-log/continew-starter-log-aop/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports rename continew-starter-log/{continew-starter-log-interceptor/src/main/java/top/continew/starter/log/interceptor => continew-starter-log-core/src/main/java/top/continew/starter/log/core}/annotation/Log.java (96%) rename continew-starter-log/continew-starter-log-core/src/main/java/top/continew/starter/log/core/{http/recordable => model}/RecordableHttpRequest.java (96%) rename continew-starter-log/continew-starter-log-core/src/main/java/top/continew/starter/log/core/{http/recordable => model}/RecordableHttpResponse.java (95%) rename continew-starter-log/continew-starter-log-interceptor/src/main/java/top/continew/starter/log/interceptor/{annotation => autoconfigure}/ConditionalOnEnabledLog.java (95%) rename continew-starter-log/{continew-starter-log-core/src/main/java/top/continew/starter/log/core/http/recordable/impl => continew-starter-log-interceptor/src/main/java/top/continew/starter/log/interceptor/handler}/RecordableServletHttpRequest.java (96%) rename continew-starter-log/{continew-starter-log-core/src/main/java/top/continew/starter/log/core/http/recordable/impl => continew-starter-log-interceptor/src/main/java/top/continew/starter/log/interceptor/handler}/RecordableServletHttpResponse.java (94%) diff --git a/continew-starter-dependencies/pom.xml b/continew-starter-dependencies/pom.xml index 1b8eeb59..136f379b 100644 --- a/continew-starter-dependencies/pom.xml +++ b/continew-starter-dependencies/pom.xml @@ -490,13 +490,6 @@ ${revision} - - - top.continew - continew-starter-log-aop - ${revision} - - top.continew @@ -687,8 +680,7 @@ - ${project.build.directory}/effective-pom/continew-starter-dependencies.xml - + ${project.build.directory}/effective-pom/continew-starter-dependencies.xml effective-pom diff --git a/continew-starter-log/continew-starter-log-aop/pom.xml b/continew-starter-log/continew-starter-log-aop/pom.xml deleted file mode 100644 index 8d2caa3e..00000000 --- a/continew-starter-log/continew-starter-log-aop/pom.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - 4.0.0 - - top.continew - continew-starter-log - ${revision} - - continew-starter-log-aop - ContiNew Starter 日志模块 - 基于 AOP 实现日志记录 - - - - - - top.continew - continew-starter-log-core - - - diff --git a/continew-starter-log/continew-starter-log-aop/src/main/java/top/continew/starter/log/aop/annotation/ConditionalOnEnabledLog.java b/continew-starter-log/continew-starter-log-aop/src/main/java/top/continew/starter/log/aop/annotation/ConditionalOnEnabledLog.java deleted file mode 100644 index a0a973a5..00000000 --- a/continew-starter-log/continew-starter-log-aop/src/main/java/top/continew/starter/log/aop/annotation/ConditionalOnEnabledLog.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved. - *

- * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.gnu.org/licenses/lgpl.html - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package top.continew.starter.log.aop.annotation; - -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import top.continew.starter.core.constant.PropertiesConstants; - -import java.lang.annotation.*; - -/** - * 是否启用日志记录注解 - * - * @author Charles7c - * @since 1.1.0 - */ -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE, ElementType.METHOD}) -@Documented -@ConditionalOnProperty(prefix = PropertiesConstants.LOG, name = PropertiesConstants.ENABLED, havingValue = "true", matchIfMissing = true) -public @interface ConditionalOnEnabledLog { -} \ No newline at end of file diff --git a/continew-starter-log/continew-starter-log-aop/src/main/java/top/continew/starter/log/aop/annotation/Log.java b/continew-starter-log/continew-starter-log-aop/src/main/java/top/continew/starter/log/aop/annotation/Log.java deleted file mode 100644 index c0521fd9..00000000 --- a/continew-starter-log/continew-starter-log-aop/src/main/java/top/continew/starter/log/aop/annotation/Log.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved. - *

- * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.gnu.org/licenses/lgpl.html - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package top.continew.starter.log.aop.annotation; - -import top.continew.starter.log.core.enums.Include; - -import java.lang.annotation.*; - -/** - * 日志注解 - *

用于接口方法或类上

- * - * @author Charles7c - * @since 1.1.0 - */ -@Documented -@Target({ElementType.METHOD, ElementType.TYPE}) -@Retention(RetentionPolicy.RUNTIME) -public @interface Log { - - /** - * 所属模块(用于接口方法或类上) - */ - String module() default ""; - - /** - * 日志描述 - 接口操作内容(仅用于接口方法上) - */ - String value() default ""; - - /** - * 包含信息(在全局配置基础上扩展包含信息) - */ - Include[] includes() default {}; - - /** - * 排除信息(在全局配置基础上减少包含信息) - */ - Include[] excludes() default {}; -} diff --git a/continew-starter-log/continew-starter-log-aop/src/main/java/top/continew/starter/log/aop/aspect/ConsoleLogAspect.java b/continew-starter-log/continew-starter-log-aop/src/main/java/top/continew/starter/log/aop/aspect/ConsoleLogAspect.java deleted file mode 100644 index 696ac3a7..00000000 --- a/continew-starter-log/continew-starter-log-aop/src/main/java/top/continew/starter/log/aop/aspect/ConsoleLogAspect.java +++ /dev/null @@ -1,80 +0,0 @@ -package top.continew.starter.log.aop.aspect; - -import com.alibaba.ttl.TransmittableThreadLocal; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; -import org.aspectj.lang.annotation.After; -import org.aspectj.lang.annotation.Aspect; -import org.aspectj.lang.annotation.Before; -import org.aspectj.lang.annotation.Pointcut; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.web.context.request.RequestContextHolder; -import org.springframework.web.context.request.ServletRequestAttributes; -import top.continew.starter.log.aop.autoconfigure.LogProperties; - -import java.time.Duration; -import java.time.Instant; - -/** - * 控制台 输出日志切面 - * - * @author echo - * @date 2024/12/06 10:33 - **/ -@Aspect -public class ConsoleLogAspect { - - private static final Logger log = LoggerFactory.getLogger(ConsoleLogAspect.class); - private final LogProperties logProperties; - private final TransmittableThreadLocal timeTtl = new TransmittableThreadLocal<>(); - - public ConsoleLogAspect(LogProperties logProperties) { - this.logProperties = logProperties; - } - - /** - * 切点 - 匹配所有控制器层的方法 - */ - @Pointcut("execution(* *..controller.*.*(..)) || execution(* *..*Controller.*(..))") - public void controllerLayer() { - } - - /** - * 处理请求前执行 - */ - @Before(value = "controllerLayer()") - public void doBefore() { - // 打印请求日志 - if (Boolean.TRUE.equals(logProperties.getIsPrint())) { - Instant startTime = Instant.now(); - ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); - if (attributes != null) { - HttpServletRequest request = attributes.getRequest(); - log.info("[{}] {}", request.getMethod(), request.getRequestURI()); - } - timeTtl.set(startTime); - } - } - - /** - * 处理请求后执行 - */ - @After(value = "controllerLayer()") - public void afterAdvice() { - // 打印请求耗时 - if (Boolean.TRUE.equals(logProperties.getIsPrint())) { - Instant endTime = Instant.now(); - ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); - if (attributes == null) { - return; - } - HttpServletRequest request = attributes.getRequest(); - HttpServletResponse response = attributes.getResponse(); - Duration timeTaken = Duration.between(timeTtl.get(), endTime); - log.info("[{}] {} {} {}ms", request.getMethod(), request.getRequestURI(), - response != null ? response.getStatus() : "N/A", - timeTaken.toMillis()); - } - } -} diff --git a/continew-starter-log/continew-starter-log-aop/src/main/java/top/continew/starter/log/aop/aspect/LogAspect.java b/continew-starter-log/continew-starter-log-aop/src/main/java/top/continew/starter/log/aop/aspect/LogAspect.java deleted file mode 100644 index 2ba06682..00000000 --- a/continew-starter-log/continew-starter-log-aop/src/main/java/top/continew/starter/log/aop/aspect/LogAspect.java +++ /dev/null @@ -1,221 +0,0 @@ -package top.continew.starter.log.aop.aspect; - -import cn.hutool.core.text.CharSequenceUtil; -import cn.hutool.core.util.StrUtil; -import com.alibaba.ttl.TransmittableThreadLocal; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; -import org.aspectj.lang.JoinPoint; -import org.aspectj.lang.annotation.*; -import org.aspectj.lang.reflect.MethodSignature; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.web.context.request.RequestContextHolder; -import org.springframework.web.context.request.ServletRequestAttributes; -import top.continew.starter.log.aop.annotation.Log; -import top.continew.starter.log.aop.autoconfigure.LogProperties; -import top.continew.starter.log.core.dao.LogDao; -import top.continew.starter.log.core.enums.Include; -import top.continew.starter.log.core.http.recordable.impl.RecordableServletHttpRequest; -import top.continew.starter.log.core.http.recordable.impl.RecordableServletHttpResponse; -import top.continew.starter.log.core.model.LogRecord; - -import java.lang.reflect.Method; -import java.time.Instant; -import java.util.HashSet; -import java.util.Set; - -/** - * 日志切面 - * - * @author echo - * @date 2024/12/06 09:58 - **/ -@Aspect -public class LogAspect { - - private static final Logger log = LoggerFactory.getLogger(LogAspect.class); - private final LogDao logDao; - private final LogProperties logProperties; - private final TransmittableThreadLocal timeTtl = new TransmittableThreadLocal<>(); - private final TransmittableThreadLocal logTtl = new TransmittableThreadLocal<>(); - - public LogAspect(LogDao logDao, LogProperties logProperties) { - this.logDao = logDao; - this.logProperties = logProperties; - } - - /** - * 切点 - 匹配日志注解 {@link Log} - */ - @Pointcut(value = "@annotation(top.continew.starter.log.aop.annotation.Log)") - public void pointcutService() { - } - - /** - * 处理请求前执行 - */ - @Before(value = "pointcutService()") - public void doBefore() { - Instant startTime = Instant.now(); - ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); - if (attributes != null) { - HttpServletRequest request = attributes.getRequest(); - LogRecord.Started startedLogRecord = LogRecord.start(startTime, new RecordableServletHttpRequest(request)); - logTtl.set(startedLogRecord); - } - } - - - /** - * 处理请求后执行 - 正常返回 - * - * @param joinPoint 切点 - */ - @After(value = "pointcutService()") - public void afterAdvice(JoinPoint joinPoint) { - handleAfterCompletion(joinPoint, null); - } - - /** - * 处理请求后执行 - 异常情况 - * - * @param joinPoint 切点 - * @param ex 异常 - */ - @AfterThrowing(pointcut = "pointcutService()", throwing = "ex") - public void afterThrowing(JoinPoint joinPoint, Exception ex) { - handleAfterCompletion(joinPoint, ex); - } - - /** - * 处理请求完成后的逻辑 - * - * @param joinPoint 切点 - * @param ex 异常 - * @param result 返回结果 - */ - private void handleAfterCompletion(JoinPoint joinPoint, Exception ex) { - try { - Instant endTime = Instant.now(); - ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); - if (attributes == null) { - return; - } - HttpServletResponse response = attributes.getResponse(); - // 处理日志记录 - LogRecord.Started startedLogRecord = logTtl.get(); - if (startedLogRecord == null) { - return; - } - - // 获取方法和类注解信息 - MethodSignature signature = (MethodSignature) joinPoint.getSignature(); - Method method = signature.getMethod(); - Class targetClass = joinPoint.getTarget().getClass(); - - Log methodLog = method.getAnnotation(Log.class); - Log classLog = targetClass.getAnnotation(Log.class); - - // 获取日志包含信息 - Set includeSet = getIncludes(methodLog, classLog); - - // 完成日志记录 - LogRecord finishedLogRecord = startedLogRecord - .finish(endTime, - new RecordableServletHttpResponse(response, response.getStatus()), - includeSet); - // 记录异常 - if (ex != null) { - finishedLogRecord.getResponse().setStatus(1); - finishedLogRecord.setErrorMsg(StrUtil.sub(ex.getMessage(), 0, 2000)); - } - - // 记录日志描述 - if (includeSet.contains(Include.DESCRIPTION)) { - logDescription(finishedLogRecord, methodLog); - } - - // 记录所属模块 - if (includeSet.contains(Include.MODULE)) { - logModule(finishedLogRecord, methodLog, classLog); - } - logDao.add(finishedLogRecord); - } catch (Exception e) { - log.error("Logging http log occurred an error: {}.", e.getMessage(), e); - } finally { - timeTtl.remove(); - logTtl.remove(); - } - } - - /** - * 获取日志包含信息 - * - * @param methodLog 方法级 Log 注解 - * @param classLog 类级 Log 注解 - * @return 日志包含信息 - */ - private Set getIncludes(Log methodLog, Log classLog) { - Set includeSet = new HashSet<>(logProperties.getIncludes()); - if (null != classLog) { - processInclude(includeSet, classLog); - } - if (null != methodLog) { - processInclude(includeSet, methodLog); - } - return includeSet; - } - - /** - * 处理日志包含信息 - * - * @param includes 日志包含信息 - * @param logAnnotation Log 注解 - */ - private void processInclude(Set includes, Log logAnnotation) { - Include[] includeArr = logAnnotation.includes(); - if (includeArr.length > 0) { - includes.addAll(Set.of(includeArr)); - } - Include[] excludeArr = logAnnotation.excludes(); - if (excludeArr.length > 0) { - includes.removeAll(Set.of(excludeArr)); - } - } - - /** - * 记录描述 - * - * @param logRecord 日志信息 - * @param methodLog 方法级 Log 注解 - */ - private void logDescription(LogRecord logRecord, Log methodLog) { - // 如果方法注解存在日志描述 - if (null != methodLog && CharSequenceUtil.isNotBlank(methodLog.value())) { - logRecord.setDescription(methodLog.value()); - } else { - logRecord.setDescription("请在该接口方法上指定日志描述"); - } - } - - /** - * 记录模块 - * - * @param logRecord 日志信息 - * @param methodLog 方法级 Log 注解 - * @param classLog 类级 Log 注解 - */ - private void logModule(LogRecord logRecord, Log methodLog, Log classLog) { - // 优先使用方法注解的模块 - if (null != methodLog && CharSequenceUtil.isNotBlank(methodLog.module())) { - logRecord.setModule(methodLog.module()); - return; - } - - // 其次使用类注解的模块 - if (null != classLog) { - logRecord.setModule(CharSequenceUtil.blankToDefault(classLog.module(), "请在该接口类上指定所属模块")); - } - } -} diff --git a/continew-starter-log/continew-starter-log-aop/src/main/java/top/continew/starter/log/aop/autoconfigure/LogAutoConfiguration.java b/continew-starter-log/continew-starter-log-aop/src/main/java/top/continew/starter/log/aop/autoconfigure/LogAutoConfiguration.java deleted file mode 100644 index 16ce2f64..00000000 --- a/continew-starter-log/continew-starter-log-aop/src/main/java/top/continew/starter/log/aop/autoconfigure/LogAutoConfiguration.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved. - *

- * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.gnu.org/licenses/lgpl.html - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package top.continew.starter.log.aop.autoconfigure; - -import jakarta.annotation.PostConstruct; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import top.continew.starter.log.aop.annotation.ConditionalOnEnabledLog; -import top.continew.starter.log.aop.aspect.ConsoleLogAspect; -import top.continew.starter.log.aop.aspect.LogAspect; -import top.continew.starter.log.core.dao.LogDao; -import top.continew.starter.log.core.dao.impl.LogDaoDefaultImpl; - -/** - * 日志自动配置 - * - * @author Charles7c - * @since 1.1.0 - */ -@Configuration -@ConditionalOnEnabledLog -@EnableConfigurationProperties(LogProperties.class) -@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET) -public class LogAutoConfiguration { - - private static final Logger log = LoggerFactory.getLogger(LogAutoConfiguration.class); - private final LogProperties logProperties; - - public LogAutoConfiguration(LogProperties logProperties) { - this.logProperties = logProperties; - } - - /** - * 记录日志切面 - * - * @return {@link LogAspect } - */ - @Bean - @ConditionalOnMissingBean - public LogAspect logAspect() { - return new LogAspect(logDao(),logProperties); - } - - /** - * 控制台输出日志切面 - * - * @return {@link LogAspect } - */ - @Bean - @ConditionalOnMissingBean - public ConsoleLogAspect consoleLogAspect() { - return new ConsoleLogAspect(logProperties); - } - - /** - * 日志持久层接口 - */ - @Bean - @ConditionalOnMissingBean - public LogDao logDao() { - return new LogDaoDefaultImpl(); - } - - @PostConstruct - public void postConstruct() { - log.debug("[ContiNew Starter] - Auto Configuration 'Log-aop' completed initialization."); - } -} diff --git a/continew-starter-log/continew-starter-log-aop/src/main/java/top/continew/starter/log/aop/autoconfigure/LogProperties.java b/continew-starter-log/continew-starter-log-aop/src/main/java/top/continew/starter/log/aop/autoconfigure/LogProperties.java deleted file mode 100644 index 4cbc1299..00000000 --- a/continew-starter-log/continew-starter-log-aop/src/main/java/top/continew/starter/log/aop/autoconfigure/LogProperties.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved. - *

- * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.gnu.org/licenses/lgpl.html - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package top.continew.starter.log.aop.autoconfigure; - -import org.springframework.boot.context.properties.ConfigurationProperties; -import top.continew.starter.core.constant.PropertiesConstants; -import top.continew.starter.log.core.enums.Include; - -import java.util.Set; - -/** - * 日志配置属性 - * - * @author Charles7c - * @since 1.1.0 - */ -@ConfigurationProperties(PropertiesConstants.LOG) -public class LogProperties { - - /** - * 是否启用日志 - */ - private boolean enabled = true; - - /** - * 是否打印日志,开启后可打印访问日志(类似于 Nginx access log) - *

- * 不记录日志也支持开启打印访问日志 - *

- */ - private Boolean isPrint = false; - - /** - * 包含信息 - */ - private Set includes = Include.defaultIncludes(); - - - public boolean isEnabled() { - return enabled; - } - - public void setEnabled(boolean enabled) { - this.enabled = enabled; - } - - public Boolean getIsPrint() { - return isPrint; - } - - public void setIsPrint(Boolean print) { - isPrint = print; - } - - public Set getIncludes() { - return includes; - } - - public void setIncludes(Set includes) { - this.includes = includes; - } -} diff --git a/continew-starter-log/continew-starter-log-aop/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/continew-starter-log/continew-starter-log-aop/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports deleted file mode 100644 index 5ee12e4c..00000000 --- a/continew-starter-log/continew-starter-log-aop/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ /dev/null @@ -1 +0,0 @@ -top.continew.starter.log.aop.autoconfigure.LogAutoConfiguration \ No newline at end of file diff --git a/continew-starter-log/continew-starter-log-interceptor/src/main/java/top/continew/starter/log/interceptor/annotation/Log.java b/continew-starter-log/continew-starter-log-core/src/main/java/top/continew/starter/log/core/annotation/Log.java similarity index 96% rename from continew-starter-log/continew-starter-log-interceptor/src/main/java/top/continew/starter/log/interceptor/annotation/Log.java rename to continew-starter-log/continew-starter-log-core/src/main/java/top/continew/starter/log/core/annotation/Log.java index 60bdff26..b8cef4fe 100644 --- a/continew-starter-log/continew-starter-log-interceptor/src/main/java/top/continew/starter/log/interceptor/annotation/Log.java +++ b/continew-starter-log/continew-starter-log-core/src/main/java/top/continew/starter/log/core/annotation/Log.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package top.continew.starter.log.interceptor.annotation; +package top.continew.starter.log.core.annotation; import top.continew.starter.log.core.enums.Include; diff --git a/continew-starter-log/continew-starter-log-core/src/main/java/top/continew/starter/log/core/model/LogRecord.java b/continew-starter-log/continew-starter-log-core/src/main/java/top/continew/starter/log/core/model/LogRecord.java index 988f13c1..9df4a49f 100644 --- a/continew-starter-log/continew-starter-log-core/src/main/java/top/continew/starter/log/core/model/LogRecord.java +++ b/continew-starter-log/continew-starter-log-core/src/main/java/top/continew/starter/log/core/model/LogRecord.java @@ -17,8 +17,6 @@ package top.continew.starter.log.core.model; import top.continew.starter.log.core.enums.Include; -import top.continew.starter.log.core.http.recordable.RecordableHttpRequest; -import top.continew.starter.log.core.http.recordable.RecordableHttpResponse; import java.time.Duration; import java.time.Instant; @@ -65,11 +63,6 @@ public class LogRecord { */ private final Instant timestamp; - /** - * 错误信息 - */ - private String errorMsg; - public LogRecord(Instant timestamp, LogRequest request, LogResponse response, Duration timeTaken) { this.timestamp = timestamp; this.request = request; @@ -171,11 +164,4 @@ public void setTimeTaken(Duration timeTaken) { public Instant getTimestamp() { return timestamp; } - - public String getErrorMsg() { - return errorMsg; - } - public void setErrorMsg(String errorMsg) { - this.errorMsg = errorMsg; - } } diff --git a/continew-starter-log/continew-starter-log-core/src/main/java/top/continew/starter/log/core/model/LogRequest.java b/continew-starter-log/continew-starter-log-core/src/main/java/top/continew/starter/log/core/model/LogRequest.java index 2fdf58c2..a13c2c8c 100644 --- a/continew-starter-log/continew-starter-log-core/src/main/java/top/continew/starter/log/core/model/LogRequest.java +++ b/continew-starter-log/continew-starter-log-core/src/main/java/top/continew/starter/log/core/model/LogRequest.java @@ -21,7 +21,6 @@ import top.continew.starter.core.util.ExceptionUtils; import top.continew.starter.core.util.IpUtils; import top.continew.starter.log.core.enums.Include; -import top.continew.starter.log.core.http.recordable.RecordableHttpRequest; import top.continew.starter.web.util.ServletUtils; import java.net.URI; diff --git a/continew-starter-log/continew-starter-log-core/src/main/java/top/continew/starter/log/core/model/LogResponse.java b/continew-starter-log/continew-starter-log-core/src/main/java/top/continew/starter/log/core/model/LogResponse.java index cf6ef7bf..a022b7c6 100644 --- a/continew-starter-log/continew-starter-log-core/src/main/java/top/continew/starter/log/core/model/LogResponse.java +++ b/continew-starter-log/continew-starter-log-core/src/main/java/top/continew/starter/log/core/model/LogResponse.java @@ -17,7 +17,6 @@ package top.continew.starter.log.core.model; import top.continew.starter.log.core.enums.Include; -import top.continew.starter.log.core.http.recordable.RecordableHttpResponse; import java.util.Map; import java.util.Set; diff --git a/continew-starter-log/continew-starter-log-core/src/main/java/top/continew/starter/log/core/http/recordable/RecordableHttpRequest.java b/continew-starter-log/continew-starter-log-core/src/main/java/top/continew/starter/log/core/model/RecordableHttpRequest.java similarity index 96% rename from continew-starter-log/continew-starter-log-core/src/main/java/top/continew/starter/log/core/http/recordable/RecordableHttpRequest.java rename to continew-starter-log/continew-starter-log-core/src/main/java/top/continew/starter/log/core/model/RecordableHttpRequest.java index 914dbc0d..b5bd3899 100644 --- a/continew-starter-log/continew-starter-log-core/src/main/java/top/continew/starter/log/core/http/recordable/RecordableHttpRequest.java +++ b/continew-starter-log/continew-starter-log-core/src/main/java/top/continew/starter/log/core/model/RecordableHttpRequest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package top.continew.starter.log.core.http.recordable; +package top.continew.starter.log.core.model; import java.net.URI; import java.util.Map; diff --git a/continew-starter-log/continew-starter-log-core/src/main/java/top/continew/starter/log/core/http/recordable/RecordableHttpResponse.java b/continew-starter-log/continew-starter-log-core/src/main/java/top/continew/starter/log/core/model/RecordableHttpResponse.java similarity index 95% rename from continew-starter-log/continew-starter-log-core/src/main/java/top/continew/starter/log/core/http/recordable/RecordableHttpResponse.java rename to continew-starter-log/continew-starter-log-core/src/main/java/top/continew/starter/log/core/model/RecordableHttpResponse.java index 28253ce4..a1ae77ee 100644 --- a/continew-starter-log/continew-starter-log-core/src/main/java/top/continew/starter/log/core/http/recordable/RecordableHttpResponse.java +++ b/continew-starter-log/continew-starter-log-core/src/main/java/top/continew/starter/log/core/model/RecordableHttpResponse.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package top.continew.starter.log.core.http.recordable; +package top.continew.starter.log.core.model; import java.util.Map; diff --git a/continew-starter-log/continew-starter-log-interceptor/src/main/java/top/continew/starter/log/interceptor/annotation/ConditionalOnEnabledLog.java b/continew-starter-log/continew-starter-log-interceptor/src/main/java/top/continew/starter/log/interceptor/autoconfigure/ConditionalOnEnabledLog.java similarity index 95% rename from continew-starter-log/continew-starter-log-interceptor/src/main/java/top/continew/starter/log/interceptor/annotation/ConditionalOnEnabledLog.java rename to continew-starter-log/continew-starter-log-interceptor/src/main/java/top/continew/starter/log/interceptor/autoconfigure/ConditionalOnEnabledLog.java index 80246c8f..69e738c6 100644 --- a/continew-starter-log/continew-starter-log-interceptor/src/main/java/top/continew/starter/log/interceptor/annotation/ConditionalOnEnabledLog.java +++ b/continew-starter-log/continew-starter-log-interceptor/src/main/java/top/continew/starter/log/interceptor/autoconfigure/ConditionalOnEnabledLog.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package top.continew.starter.log.interceptor.annotation; +package top.continew.starter.log.interceptor.autoconfigure; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import top.continew.starter.core.constant.PropertiesConstants; diff --git a/continew-starter-log/continew-starter-log-interceptor/src/main/java/top/continew/starter/log/interceptor/autoconfigure/LogAutoConfiguration.java b/continew-starter-log/continew-starter-log-interceptor/src/main/java/top/continew/starter/log/interceptor/autoconfigure/LogAutoConfiguration.java index 87f284f9..d9934f09 100644 --- a/continew-starter-log/continew-starter-log-interceptor/src/main/java/top/continew/starter/log/interceptor/autoconfigure/LogAutoConfiguration.java +++ b/continew-starter-log/continew-starter-log-interceptor/src/main/java/top/continew/starter/log/interceptor/autoconfigure/LogAutoConfiguration.java @@ -28,7 +28,6 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import top.continew.starter.log.core.dao.LogDao; import top.continew.starter.log.core.dao.impl.LogDaoDefaultImpl; -import top.continew.starter.log.interceptor.annotation.ConditionalOnEnabledLog; import top.continew.starter.log.interceptor.handler.LogFilter; import top.continew.starter.log.interceptor.handler.LogInterceptor; @@ -76,6 +75,6 @@ public LogDao logDao() { @PostConstruct public void postConstruct() { - log.debug("[ContiNew Starter] - Auto Configuration 'Log-interceptor' completed initialization."); + log.debug("[ContiNew Starter] - Auto Configuration 'Log' completed initialization."); } } diff --git a/continew-starter-log/continew-starter-log-interceptor/src/main/java/top/continew/starter/log/interceptor/handler/LogInterceptor.java b/continew-starter-log/continew-starter-log-interceptor/src/main/java/top/continew/starter/log/interceptor/handler/LogInterceptor.java index 512dceb2..9a0c27ad 100644 --- a/continew-starter-log/continew-starter-log-interceptor/src/main/java/top/continew/starter/log/interceptor/handler/LogInterceptor.java +++ b/continew-starter-log/continew-starter-log-interceptor/src/main/java/top/continew/starter/log/interceptor/handler/LogInterceptor.java @@ -28,9 +28,7 @@ import org.springframework.lang.NonNull; import org.springframework.web.method.HandlerMethod; import org.springframework.web.servlet.HandlerInterceptor; -import top.continew.starter.log.core.http.recordable.impl.RecordableServletHttpRequest; -import top.continew.starter.log.core.http.recordable.impl.RecordableServletHttpResponse; -import top.continew.starter.log.interceptor.annotation.Log; +import top.continew.starter.log.core.annotation.Log; import top.continew.starter.log.core.dao.LogDao; import top.continew.starter.log.core.enums.Include; import top.continew.starter.log.core.model.LogRecord; diff --git a/continew-starter-log/continew-starter-log-core/src/main/java/top/continew/starter/log/core/http/recordable/impl/RecordableServletHttpRequest.java b/continew-starter-log/continew-starter-log-interceptor/src/main/java/top/continew/starter/log/interceptor/handler/RecordableServletHttpRequest.java similarity index 96% rename from continew-starter-log/continew-starter-log-core/src/main/java/top/continew/starter/log/core/http/recordable/impl/RecordableServletHttpRequest.java rename to continew-starter-log/continew-starter-log-interceptor/src/main/java/top/continew/starter/log/interceptor/handler/RecordableServletHttpRequest.java index 775dbd0a..9e374691 100644 --- a/continew-starter-log/continew-starter-log-core/src/main/java/top/continew/starter/log/core/http/recordable/impl/RecordableServletHttpRequest.java +++ b/continew-starter-log/continew-starter-log-interceptor/src/main/java/top/continew/starter/log/interceptor/handler/RecordableServletHttpRequest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package top.continew.starter.log.core.http.recordable.impl; +package top.continew.starter.log.interceptor.handler; import cn.hutool.core.text.CharSequenceUtil; import cn.hutool.core.util.StrUtil; @@ -25,7 +25,7 @@ import org.springframework.web.util.UriUtils; import org.springframework.web.util.WebUtils; import top.continew.starter.core.constant.StringConstants; -import top.continew.starter.log.core.http.recordable.RecordableHttpRequest; +import top.continew.starter.log.core.model.RecordableHttpRequest; import java.net.URI; import java.net.URISyntaxException; diff --git a/continew-starter-log/continew-starter-log-core/src/main/java/top/continew/starter/log/core/http/recordable/impl/RecordableServletHttpResponse.java b/continew-starter-log/continew-starter-log-interceptor/src/main/java/top/continew/starter/log/interceptor/handler/RecordableServletHttpResponse.java similarity index 94% rename from continew-starter-log/continew-starter-log-core/src/main/java/top/continew/starter/log/core/http/recordable/impl/RecordableServletHttpResponse.java rename to continew-starter-log/continew-starter-log-interceptor/src/main/java/top/continew/starter/log/interceptor/handler/RecordableServletHttpResponse.java index c9cdccad..88ad5c57 100644 --- a/continew-starter-log/continew-starter-log-core/src/main/java/top/continew/starter/log/core/http/recordable/impl/RecordableServletHttpResponse.java +++ b/continew-starter-log/continew-starter-log-interceptor/src/main/java/top/continew/starter/log/interceptor/handler/RecordableServletHttpResponse.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package top.continew.starter.log.core.http.recordable.impl; +package top.continew.starter.log.interceptor.handler; import cn.hutool.core.text.CharSequenceUtil; import cn.hutool.core.util.StrUtil; @@ -22,7 +22,7 @@ import jakarta.servlet.http.HttpServletResponse; import org.springframework.web.util.ContentCachingResponseWrapper; import org.springframework.web.util.WebUtils; -import top.continew.starter.log.core.http.recordable.RecordableHttpResponse; +import top.continew.starter.log.core.model.RecordableHttpResponse; import top.continew.starter.web.util.ServletUtils; import java.util.Map; diff --git a/continew-starter-log/pom.xml b/continew-starter-log/pom.xml index 2b7ec476..561c4be2 100644 --- a/continew-starter-log/pom.xml +++ b/continew-starter-log/pom.xml @@ -16,7 +16,6 @@ continew-starter-log-core continew-starter-log-interceptor - continew-starter-log-aop