4 changed files with 195 additions and 24 deletions
@ -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<String, Object> requestBodyN; |
||||
|
private Map<String, Object> 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<String, Object> getRequestBodyN() { |
||||
|
return requestBodyN; |
||||
|
} |
||||
|
|
||||
|
public void setRequestBodyN(Map<String, Object> requestBodyN) { |
||||
|
this.requestBodyN = requestBodyN; |
||||
|
} |
||||
|
|
||||
|
public Map<String, Object> getResponseBodyN() { |
||||
|
return responseBodyN; |
||||
|
} |
||||
|
|
||||
|
public void setResponseBodyN(Map<String, Object> responseBodyN) { |
||||
|
this.responseBodyN = responseBodyN; |
||||
|
} |
||||
|
} |
@ -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<String, Object> map = JSONObject.parseObject(jsonObject.toJSONString(), new TypeReference<Map<String, Object>>() { |
||||
|
}); |
||||
|
log.setRequestBodyN(map); |
||||
|
|
||||
|
} |
||||
|
if (StringUtils.isNotBlank(minBoxLog.getResponseBody())) { |
||||
|
JSONObject jsonObject = JSONObject.parseObject(minBoxLog.getResponseBody()); |
||||
|
Map<String, Object> map = JSONObject.parseObject(jsonObject.toJSONString(), new TypeReference<Map<String, Object>>() { |
||||
|
}); |
||||
|
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; |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue