重新组织包结构

This commit is contained in:
白茶清欢 2025-06-06 21:46:01 +08:00
parent 688eb26c1e
commit ed6a9a5d78
9 changed files with 62 additions and 13 deletions

View File

@ -1,4 +1,4 @@
package cn.zhangdeman.filter;
package cn.zhangdeman.consts;
// http 一些枚举key
public class HttpField {

View File

@ -1,4 +1,4 @@
package cn.zhangdeman.filter;
package cn.zhangdeman.consts;
// 日志相关数据的枚举值
public class LogField {

View File

@ -1,4 +1,4 @@
package cn.zhangdeman.filter;
package cn.zhangdeman.consts;
// 记录的各种字段枚举值
public class RecordField {
@ -34,4 +34,7 @@ public class RecordField {
public static final String RESPONSE_HTTP_CODE = "http_code"; // 苍蝇状态码,默认200
public static final String RESPONSE_HEADER = "header"; // 响应header
public static final String RESPONSE_COOKIE = "cookie"; // 响应header
public static final String LOGGER_TYPE = "log_type"; // 日志类型
}

View File

@ -1,5 +1,6 @@
package cn.zhangdeman.filter;
package cn.zhangdeman.context;
import cn.zhangdeman.consts.RecordField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

View File

@ -1,5 +1,6 @@
package cn.zhangdeman.filter;
package cn.zhangdeman.context;
import cn.zhangdeman.consts.RecordField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
@ -15,6 +16,12 @@ import java.util.Map;
@Setter
@JsonIgnoreProperties(ignoreUnknown = true) // 忽略未知属性字段
public class Response {
@JsonProperty(RecordField.REQUEST_ID)
private String requestId; // 本次请求request id
@JsonProperty(RecordField.TRACE_ID)
private String traceId; // 全局trace id
@JsonProperty(RecordField.COST)
private Long cost; // 请求耗时
@JsonProperty(RecordField.RESPONSE_CODE)
private String code; // 响应业务状态码
@JsonProperty(RecordField.RESPONSE_MESSAGE)

View File

@ -1,5 +1,6 @@
package cn.zhangdeman.filter;
package cn.zhangdeman.context;
import cn.zhangdeman.consts.RecordField;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;

View File

@ -1,7 +0,0 @@
package cn.zhangdeman.filter;
public class Main {
public static void main(String[] args) {
}
}

View File

@ -1,6 +1,10 @@
package cn.zhangdeman.filter;
import cn.zhangdeman.consts.RecordField;
import cn.zhangdeman.context.Request;
import cn.zhangdeman.context.Response;
import cn.zhangdeman.context.RuntimeContext;
import jakarta.servlet.FilterChain;
import jakarta.servlet.FilterConfig;
import jakarta.servlet.ServletException;

View File

@ -0,0 +1,40 @@
package cn.zhangdeman.logger;
import cn.zhangdeman.consts.RecordField;
import cn.zhangdeman.context.Request;
import cn.zhangdeman.context.Response;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.Setter;
import java.util.Map;
// 日志数据结构
@Setter
@Getter
@JsonIgnoreProperties(ignoreUnknown = true) // 忽略未知属性字段
public class LogData {
@JsonProperty(RecordField.LOGGER_TYPE)
private String LogType;
@JsonProperty(RecordField.REQUEST_ID)
private String requestId; // 本次请求request id
@JsonProperty(RecordField.COST)
private Long cost; // 请求耗时
@JsonProperty(RecordField.SERVER_IP)
private String serverIp; // 服务器Ip
@JsonProperty(RecordField.SERVER_HOSTNAME)
private String serverHostname; // 服务器hostname
@JsonProperty(RecordField.FINISH_TIMESTAMP)
private Long finishTimeStamp; // 完成请求时间
@JsonProperty(RecordField.TRACE_ID)
private String traceId; // 全局trace id
@JsonProperty(RecordField.START_TIMESTAMP)
private Long startTimeStamp; // 开始请求时间
@JsonProperty(RecordField.CONTEXT_DATA)
private Map<String, Object> logData; // 本条日志的上下文信息
@JsonProperty(RecordField.REQUEST_INFO)
private Request requestInfo;// 请求信息
@JsonProperty(RecordField.RESPONSE_INFO)
private Response responseInfo; // 响应信息
}