当前位置:网站首页>Feign requests the log to be printed uniformly
Feign requests the log to be printed uniformly
2022-04-23 18:11:00 【dawnsun001】
@Slf4j
public class FeignLogger extends feign.Logger {
static ThreadLocal<Map<String, String>> logContext = new ThreadLocal();
static String PATH = "path";
static String METHOD = "method";
static String REQUEST_BODY = "body";
static String ELAPSED_TIME = " Time consuming ";
static String ELAPSED_TIME_UNIT = " millisecond ";
static String FEIGN_INVOKE_LOGGER = "feign Interface call ";
@Override
protected void logRequest(String configKey, Level logLevel, Request request) {
Map<String, String> logMap = new HashMap<>(3);
logMap.put(PATH, request.url());
logMap.put(METHOD, request.method());
logMap.put(REQUEST_BODY, request.body() == null ? null :
request.charset() == null ? null : new String(request.body(), request.charset()));
logContext.set(logMap);
}
@Override
protected Response logAndRebufferResponse(
String configKey, Level logLevel, Response response, long elapsedTime) throws IOException {
Map<String, String> requetParam = logContext.get();
StringBuilder stringBuilder = new StringBuilder();
stringBuilder
.append(FEIGN_INVOKE_LOGGER).append(" ")
.append(requetParam.get(METHOD)).append(" ")
.append(response.status()).append(" ")
.append(requetParam.get(PATH)).append(" ")
.append(ELAPSED_TIME).append(elapsedTime).append(ELAPSED_TIME_UNIT);
if (requetParam.get(REQUEST_BODY) != null) {
stringBuilder.append(" Request entry :").append(requetParam.get(REQUEST_BODY));
}
logContext.remove();
// Returns the parameter
if (response.body() != null && !(response.status() == 204 || response.status() == 205)) {
byte[] bodyData = Util.toByteArray(response.body().asInputStream());
if (bodyData.length > 0) {
String responseBody = decodeOrDefault(bodyData, UTF_8, "Binary data");
stringBuilder
.append(" Return value :")
.append(responseBody.replaceAll("\\s*|\t|\r|\n", ""));
}
log.info(stringBuilder.toString());
return response.toBuilder().body(bodyData).build();
}
log.info(stringBuilder.toString());
return response;
}
protected IOException logIOException(String configKey, Level logLevel, IOException ioe, long elapsedTime) {
Map<String, String> requetParam = logContext.get();
StringBuilder stringBuilder = new StringBuilder();
stringBuilder
.append(FEIGN_INVOKE_LOGGER).append(" ")
.append(requetParam.get(METHOD)).append(" ")
.append(ioe.getClass().getSimpleName()).append(" ")
.append(requetParam.get(PATH)).append(" ")
.append(ELAPSED_TIME).append(elapsedTime).append(ELAPSED_TIME_UNIT);;
if (requetParam.get(REQUEST_BODY) != null) {
stringBuilder.append(" Request entry :").append(requetParam.get(REQUEST_BODY));
}
log.warn(stringBuilder.toString());
logContext.remove();
return ioe;
}
@Override
protected void log(String configKey, String format, Object... args) {
if (log.isInfoEnabled()) {
log.info(String.format(methodTag(configKey) + format, args));
}
}
}
版权声明
本文为[dawnsun001]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230544289018.html
边栏推荐
- RC smart pointer in rust
- ArcGIS license error -15 solution
- Docker installation MySQL
- MySQL auto start settings start with systemctl start mysqld
- Mode of interprocess communication
- I / O multiplexing and its related details
- JD-FreeFuck 京東薅羊毛控制面板 後臺命令執行漏洞
- Queue solving Joseph problem
- ArcGIS table to excel exceeds the upper limit, conversion failed
- 2022 Jiangxi energy storage technology exhibition, China Battery exhibition, power battery exhibition and fuel cell Exhibition
猜你喜欢

【ACM】70. 爬楼梯

Process management command

Implementation of object detection case based on SSD
![[UDS unified diagnostic service] IV. typical diagnostic service (6) - input / output control unit (0x2F)](/img/ae/cbfc01fbcc816915b1794a9d70247a.png)
[UDS unified diagnostic service] IV. typical diagnostic service (6) - input / output control unit (0x2F)

MySQL auto start settings start with systemctl start mysqld

Robocode tutorial 7 - Radar locking

【ACM】376. 摆动序列

An example of linear regression based on tensorflow

JD-FreeFuck 京东薅羊毛控制面板 后台命令执行漏洞

C# 网络相关操作
随机推荐
Visualization of residential house prices
C medium? This form of
YOLOv4剪枝【附代码】
Flash operates on multiple databases
re正则表达式
idea中安装YapiUpload 插件将api接口上传到yapi文档上
Permission management with binary
How to read literature
Classes and objects
Docker 安装 MySQL
C [file operation] read TXT text by line
Correct opening method of option
PowerDesigner various font settings; Preview font setting; SQL font settings
Win1远程出现“这可能是由于credssp加密oracle修正”解决办法
JD freefuck Jingdong HaoMao control panel background Command Execution Vulnerability
mysql自动启动设置用Systemctl start mysqld启动
Secure credit
Differences between SSD hard disk SATA interface and m.2 interface (detailed summary)
ArcGIS table to excel exceeds the upper limit, conversion failed
Nodejs安装