mirror of
https://github.com/continew-org/continew-starter.git
synced 2025-09-10 08:57:19 +08:00
refactor(log): 优化基于 AOP 实现日志代码,调整日志整体包结构
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
||||
* <p>
|
||||
* 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
|
||||
* <p>
|
||||
* http://www.gnu.org/licenses/lgpl.html
|
||||
* <p>
|
||||
* 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.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 {
|
||||
}
|
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
||||
* <p>
|
||||
* 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
|
||||
* <p>
|
||||
* http://www.gnu.org/licenses/lgpl.html
|
||||
* <p>
|
||||
* 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.annotation;
|
||||
|
||||
import top.continew.starter.log.enums.Include;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* 日志注解
|
||||
* <p>用于接口方法或类上,辅助 Spring Doc 使用效果最佳</p>
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 1.1.0
|
||||
*/
|
||||
@Documented
|
||||
@Target({ElementType.METHOD, ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Log {
|
||||
|
||||
/**
|
||||
* 日志描述(仅用于接口方法上)
|
||||
* <p>
|
||||
* 优先级:@Log("描述") > @Operation(summary="描述")
|
||||
* </p>
|
||||
*/
|
||||
String value() default "";
|
||||
|
||||
/**
|
||||
* 所属模块(用于接口方法或类上)
|
||||
* <p>
|
||||
* 优先级: 接口方法上的 @Log(module = "模块") > 接口类上的 @Log(module = "模块") > @Tag(name = "模块") 内容
|
||||
* </p>
|
||||
*/
|
||||
String module() default "";
|
||||
|
||||
/**
|
||||
* 包含信息(在全局配置基础上扩展包含信息)
|
||||
*/
|
||||
Include[] includes() default {};
|
||||
|
||||
/**
|
||||
* 排除信息(在全局配置基础上减少包含信息)
|
||||
*/
|
||||
Include[] excludes() default {};
|
||||
|
||||
/**
|
||||
* 是否忽略日志记录(用于接口方法或类上)
|
||||
*/
|
||||
boolean ignore() default false;
|
||||
}
|
@@ -14,9 +14,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.continew.starter.log.core.dao;
|
||||
package top.continew.starter.log.dao;
|
||||
|
||||
import top.continew.starter.log.core.model.LogRecord;
|
||||
import top.continew.starter.log.model.LogRecord;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
@@ -14,10 +14,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.continew.starter.log.core.dao.impl;
|
||||
package top.continew.starter.log.dao.impl;
|
||||
|
||||
import top.continew.starter.log.core.dao.LogDao;
|
||||
import top.continew.starter.log.core.model.LogRecord;
|
||||
import top.continew.starter.log.dao.LogDao;
|
||||
import top.continew.starter.log.model.LogRecord;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
@@ -30,7 +30,7 @@ import java.util.List;
|
||||
* @author Charles7c
|
||||
* @since 1.1.0
|
||||
*/
|
||||
public class LogDaoDefaultImpl implements LogDao {
|
||||
public class DefaultLogDaoImpl implements LogDao {
|
||||
|
||||
/**
|
||||
* 容量
|
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.continew.starter.log.core.enums;
|
||||
package top.continew.starter.log.enums;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.continew.starter.log.core.http.recordable;
|
||||
package top.continew.starter.log.http.recordable;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.continew.starter.log.core.http.recordable;
|
||||
package top.continew.starter.log.http.recordable;
|
||||
|
||||
import java.util.Map;
|
||||
|
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.continew.starter.log.core.http.recordable.impl;
|
||||
package top.continew.starter.log.http.recordable.impl;
|
||||
|
||||
import cn.hutool.core.text.CharSequenceUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
@@ -25,7 +25,7 @@ import org.springframework.web.util.ContentCachingRequestWrapper;
|
||||
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.http.recordable.RecordableHttpRequest;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.continew.starter.log.core.http.recordable.impl;
|
||||
package top.continew.starter.log.http.recordable.impl;
|
||||
|
||||
import cn.hutool.core.text.CharSequenceUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
@@ -22,7 +22,7 @@ import cn.hutool.json.JSONUtil;
|
||||
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.http.recordable.RecordableHttpResponse;
|
||||
import top.continew.starter.web.util.ServletUtils;
|
||||
|
||||
import java.util.Map;
|
@@ -14,11 +14,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.continew.starter.log.core.model;
|
||||
package top.continew.starter.log.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 top.continew.starter.log.enums.Include;
|
||||
import top.continew.starter.log.http.recordable.RecordableHttpRequest;
|
||||
import top.continew.starter.log.http.recordable.RecordableHttpResponse;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
@@ -115,9 +115,9 @@ public class LogRecord {
|
||||
/**
|
||||
* 结束日志记录
|
||||
*
|
||||
* @param clock 时间
|
||||
* @param response 响应信息
|
||||
* @param includes 包含信息
|
||||
* @param timestamp 结束时间
|
||||
* @param response 响应信息
|
||||
* @param includes 包含信息
|
||||
* @return 日志记录
|
||||
*/
|
||||
public LogRecord finish(Instant timestamp, RecordableHttpResponse response, Set<Include> includes) {
|
||||
@@ -172,11 +172,11 @@ public class LogRecord {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
public String getErrorMsg() {
|
||||
return errorMsg;
|
||||
}
|
||||
|
||||
public void setErrorMsg(String errorMsg) {
|
||||
this.errorMsg = errorMsg;
|
||||
}
|
||||
|
||||
public String getErrorMsg() {
|
||||
return errorMsg;
|
||||
}
|
||||
}
|
@@ -14,14 +14,14 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.continew.starter.log.core.model;
|
||||
package top.continew.starter.log.model;
|
||||
|
||||
import cn.hutool.core.text.CharSequenceUtil;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
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.log.enums.Include;
|
||||
import top.continew.starter.log.http.recordable.RecordableHttpRequest;
|
||||
import top.continew.starter.web.util.ServletUtils;
|
||||
|
||||
import java.net.URI;
|
@@ -14,10 +14,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.continew.starter.log.core.model;
|
||||
package top.continew.starter.log.model;
|
||||
|
||||
import top.continew.starter.log.core.enums.Include;
|
||||
import top.continew.starter.log.core.http.recordable.RecordableHttpResponse;
|
||||
import top.continew.starter.log.enums.Include;
|
||||
import top.continew.starter.log.http.recordable.RecordableHttpResponse;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
Reference in New Issue
Block a user