diff --git a/yxt-common/yxt-common-base/pom.xml b/yxt-common/yxt-common-base/pom.xml index a7cc522..35c4cf0 100644 --- a/yxt-common/yxt-common-base/pom.xml +++ b/yxt-common/yxt-common-base/pom.xml @@ -176,6 +176,11 @@ 1.18 + + org.minbox.framework + api-boot-starter-logging + + diff --git a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/config/logging/Log.java b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/config/logging/Log.java new file mode 100644 index 0000000..97e8efb --- /dev/null +++ b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/config/logging/Log.java @@ -0,0 +1,96 @@ +package com.yxt.common.base.config.logging; + +import java.io.Serializable; +import java.util.Map; + +/** + * @Author dimengzhe + * @Date 2022/6/21 15:48 + * @Description + */ +public class Log implements Serializable { + + private static final long serialVersionUID = 3958980733637576088L; + private String serviceId; + private String requestIp; + private String serviceIp; + private String servicePort; + private Integer httpStatus; + private String requestMethod; + private String requestUri; + + private Map requestBodyN; + private Map responseBodyN; + + public String getRequestMethod() { + return requestMethod; + } + + public void setRequestMethod(String requestMethod) { + this.requestMethod = requestMethod; + } + + public String getRequestUri() { + return requestUri; + } + + public void setRequestUri(String requestUri) { + this.requestUri = requestUri; + } + + public Integer getHttpStatus() { + return httpStatus; + } + + public void setHttpStatus(Integer httpStatus) { + this.httpStatus = httpStatus; + } + + public String getRequestIp() { + return requestIp; + } + + public void setRequestIp(String requestIp) { + this.requestIp = requestIp; + } + + public String getServiceIp() { + return serviceIp; + } + + public void setServiceIp(String serviceIp) { + this.serviceIp = serviceIp; + } + + public String getServicePort() { + return servicePort; + } + + public void setServicePort(String servicePort) { + this.servicePort = servicePort; + } + + public String getServiceId() { + return serviceId; + } + + public void setServiceId(String serviceId) { + this.serviceId = serviceId; + } + + public Map getRequestBodyN() { + return requestBodyN; + } + + public void setRequestBodyN(Map requestBodyN) { + this.requestBodyN = requestBodyN; + } + + public Map getResponseBodyN() { + return responseBodyN; + } + + public void setResponseBodyN(Map responseBodyN) { + this.responseBodyN = responseBodyN; + } +} diff --git a/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/config/logging/LoggingLocalNotice.java b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/config/logging/LoggingLocalNotice.java new file mode 100644 index 0000000..77bdb08 --- /dev/null +++ b/yxt-common/yxt-common-base/src/main/java/com/yxt/common/base/config/logging/LoggingLocalNotice.java @@ -0,0 +1,64 @@ +package com.yxt.common.base.config.logging; + +import cn.hutool.core.bean.BeanUtil; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.TypeReference; +import org.apache.commons.lang3.StringUtils; +import org.minbox.framework.logging.client.LoggingFactoryBean; +import org.minbox.framework.logging.client.notice.LoggingNotice; +import org.minbox.framework.logging.core.MinBoxLog; +import org.minbox.framework.util.JsonUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +import java.util.Map; + +/** + * @Author dimengzhe + * @Date 2022/6/21 11:27 + * @Description 日志模板 + */ +@Component +public class LoggingLocalNotice implements LoggingNotice { + + public static final String BEAN_NAME = "loggingLocalNotice"; + static Logger logger = LoggerFactory.getLogger(LoggingLocalNotice.class); + private final LoggingFactoryBean loggingFactoryBean; + + public LoggingLocalNotice(LoggingFactoryBean loggingFactoryBean) { + this.loggingFactoryBean = loggingFactoryBean; + } + + @Override + public void notice(MinBoxLog minBoxLog) { + if (this.loggingFactoryBean.isShowConsoleLog()) { + logger.info("=====接口开始:" + minBoxLog.getRequestUri()); + Log log = new Log(); + if (StringUtils.isNotBlank(minBoxLog.getRequestBody())) { + JSONObject jsonObject = JSONObject.parseObject(minBoxLog.getRequestBody()); + Map map = JSONObject.parseObject(jsonObject.toJSONString(), new TypeReference>() { + }); + log.setRequestBodyN(map); + + } + if (StringUtils.isNotBlank(minBoxLog.getResponseBody())) { + JSONObject jsonObject = JSONObject.parseObject(minBoxLog.getResponseBody()); + Map map = JSONObject.parseObject(jsonObject.toJSONString(), new TypeReference>() { + }); + log.setResponseBodyN(map); + } + log.setHttpStatus(minBoxLog.getHttpStatus()); + BeanUtil.copyProperties(minBoxLog, log); +// logger.info("Request Uri:{}, Logging:\n{}", minBoxLog.getRequestUri(), this.loggingFactoryBean.isFormatConsoleLog() ? JsonUtils.beautifyJson(minBoxLog) : JsonUtils.toJsonString(minBoxLog)); + logger.info("Logging:\n{}", this.loggingFactoryBean.isFormatConsoleLog() ? JsonUtils.beautifyJson(log) : JsonUtils.toJsonString(log)); + logger.info("====接口结束"); + } + + } + + @Override + public int getOrder() { + return -2147483648; + } +} diff --git a/yxt-parent/pom.xml b/yxt-parent/pom.xml index 7eb7984..49da0ff 100644 --- a/yxt-parent/pom.xml +++ b/yxt-parent/pom.xml @@ -55,7 +55,7 @@ 2.9.2 2.0.5 - + 3.17 @@ -127,11 +127,11 @@ - - com.auth0 - java-jwt - ${java-jwt.version} - + + com.auth0 + java-jwt + ${java-jwt.version} + redis.clients @@ -185,7 +185,7 @@ - + io.springfox springfox-swagger2 ${swagger.fox.version} @@ -202,21 +202,21 @@ pom import - + org.apache.poi @@ -400,8 +400,14 @@ - - + + + org.minbox.framework + api-boot-dependencies + 2.3.3.RELEASE + pom + import +