项目添加日志文件打印
This commit is contained in:
@@ -176,6 +176,11 @@
|
||||
<version>1.18</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.minbox.framework</groupId>
|
||||
<artifactId>api-boot-starter-logging</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -55,7 +55,7 @@
|
||||
<!-- Swagger 依赖配置 -->
|
||||
<swagger.fox.version>2.9.2</swagger.fox.version>
|
||||
<knife4j-Swagger>2.0.5</knife4j-Swagger>
|
||||
<!-- <knife4j-Swagger>3.0.3</knife4j-Swagger>-->
|
||||
<!-- <knife4j-Swagger>3.0.3</knife4j-Swagger>-->
|
||||
<!-- excel工具 -->
|
||||
<poi.version>3.17</poi.version>
|
||||
<!-- 验证码 -->
|
||||
@@ -127,11 +127,11 @@
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/com.auth0/java-jwt -->
|
||||
<dependency>
|
||||
<groupId>com.auth0</groupId>
|
||||
<artifactId>java-jwt</artifactId>
|
||||
<version>${java-jwt.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.auth0</groupId>
|
||||
<artifactId>java-jwt</artifactId>
|
||||
<version>${java-jwt.version}</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/redis.clients/jedis -->
|
||||
<dependency>
|
||||
<groupId>redis.clients</groupId>
|
||||
@@ -185,7 +185,7 @@
|
||||
</dependency>
|
||||
|
||||
<!-- Swagger 依赖配置 -->
|
||||
<dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
<version>${swagger.fox.version}</version>
|
||||
@@ -202,21 +202,21 @@
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<!-- <dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-spring-ui</artifactId>
|
||||
<version>${knife4j-Swagger}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-micro-spring-boot-starter</artifactId>
|
||||
<version>${knife4j-Swagger}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-spring-boot-starter</artifactId>
|
||||
<version>${knife4j-Swagger}</version>
|
||||
</dependency>-->
|
||||
<!-- <dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-spring-ui</artifactId>
|
||||
<version>${knife4j-Swagger}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-micro-spring-boot-starter</artifactId>
|
||||
<version>${knife4j-Swagger}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-spring-boot-starter</artifactId>
|
||||
<version>${knife4j-Swagger}</version>
|
||||
</dependency>-->
|
||||
<!-- excel工具 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
@@ -400,8 +400,14 @@
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!--ApiBoot Logging日志管理文件-->
|
||||
<dependency>
|
||||
<groupId>org.minbox.framework</groupId>
|
||||
<artifactId>api-boot-dependencies</artifactId>
|
||||
<version>2.3.3.RELEASE</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
Reference in New Issue
Block a user