Logging.java 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. package com.simuwang.logging;
  2. import com.simuwang.base.common.conts.Constants;
  3. import java.io.Serial;
  4. import java.io.Serializable;
  5. /**
  6. * @author wangzaijun
  7. * @date 2024/9/14 14:04
  8. * @description 系统操作日志记录
  9. */
  10. public class Logging implements Serializable {
  11. public static final long serialVersionUID = Constants.DEFAULT_SERIAL_ID;
  12. private String title;
  13. private Integer type;
  14. private String requestUri;
  15. private String method;
  16. private String remoteAddr;
  17. private Long executeTime;
  18. private String params;
  19. private String result;
  20. private Boolean hasException;
  21. private String exception;
  22. /**
  23. * 私有化无参构造器
  24. */
  25. private Logging() {
  26. }
  27. /**
  28. * 提供一个包含所有参数的构造器,方便子类继承后扩展
  29. *
  30. * @param title 标题
  31. * @param type 日志类型
  32. * @param requestUri 请求地址
  33. * @param method 请求method
  34. * @param params 请求参数
  35. * @param result 执行结果
  36. * @param executeTime 执行所用时间,单位:毫秒
  37. * @param hasException 是否有异常
  38. * @param exception 异常详情
  39. */
  40. public Logging(String title, Integer type, String requestUri, String method, String remoteAddr, Long executeTime,
  41. String params, String result, Boolean hasException, String exception) {
  42. this.title = title;
  43. this.type = type;
  44. this.requestUri = requestUri;
  45. this.method = method;
  46. this.remoteAddr = remoteAddr;
  47. this.executeTime = executeTime;
  48. this.params = params;
  49. this.result = result;
  50. this.hasException = hasException;
  51. this.exception = exception;
  52. }
  53. /**
  54. * 一个构造logging的builder对象的方法
  55. *
  56. * @return Builder对象
  57. */
  58. public static Builder builder() {
  59. return new Builder();
  60. }
  61. @Override
  62. public String toString() {
  63. return "{title='" + title + '\'' +
  64. ", requestUri='" + requestUri + '\'' +
  65. ", remoteAddr='" + remoteAddr + '\'' +
  66. ", executeTime=" + executeTime + '}';
  67. }
  68. public String getTitle() {
  69. return title;
  70. }
  71. public Integer getType() {
  72. return type;
  73. }
  74. public String getRequestUri() {
  75. return requestUri;
  76. }
  77. public String getMethod() {
  78. return method;
  79. }
  80. public String getRemoteAddr() {
  81. return remoteAddr;
  82. }
  83. public Long getExecuteTime() {
  84. return executeTime;
  85. }
  86. public String getParams() {
  87. return params;
  88. }
  89. public String getResult() {
  90. return result;
  91. }
  92. public String getException() {
  93. return exception;
  94. }
  95. public Boolean getHasException() {
  96. return hasException;
  97. }
  98. /**
  99. * logging a builder
  100. */
  101. public static class Builder implements Serializable {
  102. @Serial
  103. private static final long serialVersionUID = Constants.DEFAULT_SERIAL_ID;
  104. private String title;
  105. private Integer type;
  106. private String requestUri;
  107. private String method;
  108. private String remoteAddr;
  109. private Long executeTime;
  110. private String params;
  111. private String result;
  112. private Boolean hasException;
  113. private String exception;
  114. private Builder() {
  115. }
  116. public Builder title(String title) {
  117. this.title = title;
  118. return this;
  119. }
  120. public Builder type(int type) {
  121. this.type = type;
  122. return this;
  123. }
  124. public Builder requestUri(String requestUri) {
  125. this.requestUri = requestUri;
  126. return this;
  127. }
  128. public Builder method(String method) {
  129. this.method = method;
  130. return this;
  131. }
  132. public Builder remoteAddr(String remoteAddr) {
  133. this.remoteAddr = remoteAddr;
  134. return this;
  135. }
  136. public Builder params(String params) {
  137. this.params = params;
  138. return this;
  139. }
  140. public void result(String result) {
  141. this.result = result;
  142. }
  143. public void executeTime(Long executeTime) {
  144. this.executeTime = executeTime;
  145. }
  146. public void hasException(Boolean hasException) {
  147. this.hasException = hasException;
  148. }
  149. public void exception(String exception) {
  150. this.exception = exception;
  151. }
  152. public Logging build() {
  153. Logging logging = new Logging();
  154. logging.title = this.title;
  155. logging.type = this.type;
  156. logging.requestUri = this.requestUri;
  157. logging.method = this.method;
  158. logging.remoteAddr = this.remoteAddr;
  159. logging.params = this.params;
  160. logging.result = this.result;
  161. logging.executeTime = this.executeTime;
  162. logging.hasException = this.hasException;
  163. logging.exception = this.exception;
  164. return logging;
  165. }
  166. }
  167. }