package com.simuwang.logging; import com.simuwang.base.common.conts.Constants; import java.io.Serial; import java.io.Serializable; /** * @author wangzaijun * @date 2024/9/14 14:04 * @description 系统操作日志记录 */ public class Logging implements Serializable { public static final long serialVersionUID = Constants.DEFAULT_SERIAL_ID; private String title; private Integer type; private String requestUri; private String method; private String remoteAddr; private Long executeTime; private String params; private String result; private Boolean hasException; private String exception; /** * 私有化无参构造器 */ private Logging() { } /** * 提供一个包含所有参数的构造器,方便子类继承后扩展 * * @param title 标题 * @param type 日志类型 * @param requestUri 请求地址 * @param method 请求method * @param params 请求参数 * @param result 执行结果 * @param executeTime 执行所用时间,单位:毫秒 * @param hasException 是否有异常 * @param exception 异常详情 */ public Logging(String title, Integer type, String requestUri, String method, String remoteAddr, Long executeTime, String params, String result, Boolean hasException, String exception) { this.title = title; this.type = type; this.requestUri = requestUri; this.method = method; this.remoteAddr = remoteAddr; this.executeTime = executeTime; this.params = params; this.result = result; this.hasException = hasException; this.exception = exception; } /** * 一个构造logging的builder对象的方法 * * @return Builder对象 */ public static Builder builder() { return new Builder(); } @Override public String toString() { return "{title='" + title + '\'' + ", requestUri='" + requestUri + '\'' + ", remoteAddr='" + remoteAddr + '\'' + ", executeTime=" + executeTime + '}'; } public String getTitle() { return title; } public Integer getType() { return type; } public String getRequestUri() { return requestUri; } public String getMethod() { return method; } public String getRemoteAddr() { return remoteAddr; } public Long getExecuteTime() { return executeTime; } public String getParams() { return params; } public String getResult() { return result; } public String getException() { return exception; } public Boolean getHasException() { return hasException; } /** * logging a builder */ public static class Builder implements Serializable { @Serial private static final long serialVersionUID = Constants.DEFAULT_SERIAL_ID; private String title; private Integer type; private String requestUri; private String method; private String remoteAddr; private Long executeTime; private String params; private String result; private Boolean hasException; private String exception; private Builder() { } public Builder title(String title) { this.title = title; return this; } public Builder type(int type) { this.type = type; return this; } public Builder requestUri(String requestUri) { this.requestUri = requestUri; return this; } public Builder method(String method) { this.method = method; return this; } public Builder remoteAddr(String remoteAddr) { this.remoteAddr = remoteAddr; return this; } public Builder params(String params) { this.params = params; return this; } public void result(String result) { this.result = result; } public void executeTime(Long executeTime) { this.executeTime = executeTime; } public void hasException(Boolean hasException) { this.hasException = hasException; } public void exception(String exception) { this.exception = exception; } public Logging build() { Logging logging = new Logging(); logging.title = this.title; logging.type = this.type; logging.requestUri = this.requestUri; logging.method = this.method; logging.remoteAddr = this.remoteAddr; logging.params = this.params; logging.result = this.result; logging.executeTime = this.executeTime; logging.hasException = this.hasException; logging.exception = this.exception; return logging; } } }