2 changed files with 110 additions and 2 deletions
@ -0,0 +1,108 @@ |
|||
package com.qs.serve.modules.third.util; |
|||
|
|||
import lombok.Data; |
|||
import org.springframework.http.HttpEntity; |
|||
import org.springframework.http.HttpHeaders; |
|||
import org.springframework.http.client.SimpleClientHttpRequestFactory; |
|||
import org.springframework.web.client.RestTemplate; |
|||
|
|||
/** |
|||
* 日志平台工具类(Spring版本) |
|||
* @author YenHex |
|||
* @since 2023/12/21 |
|||
*/ |
|||
public class ThirdRequestLogUtil { |
|||
|
|||
/* |
|||
public static void main(String[] args) { |
|||
ThirtyRequestLog requestLog = new ThirtyRequestLog(); |
|||
requestLog.setTitle("test"); |
|||
requestLog.setModule("test"); |
|||
requestLog.setRequestJson("{}"); |
|||
requestLog.setResponseJson("{}"); |
|||
requestLog.setKey1("A100"); |
|||
requestLog.setKey2("A100"); |
|||
requestLog.setKey3("A100"); |
|||
requestLog.setErrorMsg("A100"); |
|||
requestLog.setLogLevel("info"); |
|||
requestLog.setSuccessStatus(1); |
|||
requestLog.setRemark("A100"); |
|||
requestLog.setExtValue1("A100"); |
|||
requestLog.setExtValue2("A100"); |
|||
requestLog.setExtValue3("A100"); |
|||
requestLog.setExtValue4("A100"); |
|||
|
|||
String rs = ThirdRequestLogUtil.post(requestLog); |
|||
System.out.println(rs); |
|||
}*/ |
|||
|
|||
private static final String SAVE_LOG_URL = "http://192.168.0.9:7100/api/reqLog/saveLog"; |
|||
|
|||
private static RestTemplate restTemplate; |
|||
|
|||
private static RestTemplate getRestTemplate(){ |
|||
if(restTemplate==null){ |
|||
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory(); |
|||
factory.setReadTimeout(5000); |
|||
factory.setConnectTimeout(15000); |
|||
restTemplate = new RestTemplate(factory); |
|||
} |
|||
return restTemplate; |
|||
} |
|||
|
|||
public static String post(ThirtyRequestLog requestLog) { |
|||
HttpHeaders headers = new HttpHeaders(); |
|||
HttpEntity<ThirtyRequestLog> formEntity = new HttpEntity<>(requestLog,headers); |
|||
return getRestTemplate().postForObject(SAVE_LOG_URL,formEntity, String.class); |
|||
} |
|||
|
|||
@Data |
|||
public static class ThirtyRequestLog{ |
|||
|
|||
/** 标题 长度255 */ |
|||
private String title; |
|||
|
|||
/** 业务模块 长度255 */ |
|||
private String module; |
|||
|
|||
/** 请求json 只接受json */ |
|||
private String requestJson; |
|||
|
|||
/** 返回json 只接受json */ |
|||
private String responseJson; |
|||
|
|||
/** 键id_1 长度255 */ |
|||
private String key1; |
|||
|
|||
/** 键id_2 长度255 */ |
|||
private String key2; |
|||
|
|||
/** 键id_3 长度255 */ |
|||
private String key3; |
|||
|
|||
/** 错误信息 长度不能超过1255字 */ |
|||
private String errorMsg; |
|||
|
|||
/** 严重程度:info,warning,error */ |
|||
private String logLevel; |
|||
|
|||
/** 状态:0-不成功,需要处理;1-成功 */ |
|||
private Integer successStatus; |
|||
|
|||
/** 备注 长度不能超过255字 */ |
|||
private String remark; |
|||
|
|||
/** 拓展1 长度不能超过255字 */ |
|||
private String extValue1; |
|||
|
|||
/** 拓展2 长度不能超过255字 */ |
|||
private String extValue2; |
|||
|
|||
/** 拓展3 长度不能超过255字 */ |
|||
private String extValue3; |
|||
|
|||
/** 拓展4 长度不能超过255字 */ |
|||
private String extValue4; |
|||
} |
|||
|
|||
} |
Loading…
Reference in new issue