Skip to content

Commit

Permalink
logging 格式优化
Browse files Browse the repository at this point in the history
  • Loading branch information
yhyzgn committed Jul 25, 2021
1 parent 381348f commit c8c4535
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public Response intercept(@NotNull Chain chain) throws IOException {
RequestBody reqBody = request.body();
if (null != reqBody) {
lines.empty().line("-- Request Body --");
lines.line(requestBodyToString(reqBody));
lines.line(requestBodyToString(reqBody).replace(System.lineSeparator(), System.lineSeparator() + "│ "));
}

Response response = chain.proceed(request);
Expand Down Expand Up @@ -80,7 +80,7 @@ public Response intercept(@NotNull Chain chain) throws IOException {
}
String content = source.readUtf8();
lines.empty().line("-- Response Body --");
lines.line(content);
lines.line(content.replace(System.lineSeparator(), System.lineSeparator() + "│ "));

// 重组 Response
// 须移除 Content-Encoding,因为当前 body 已解压
Expand All @@ -101,16 +101,16 @@ public Response intercept(@NotNull Chain chain) throws IOException {
private void log(Object tag, LogLines lines) {
StringBuffer sb = new StringBuffer(System.lineSeparator());
sb
.append("┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────")
.append("┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────")
.append(System.lineSeparator())
.append("│ ").append(tag.toString())
.append(System.lineSeparator())
.append("├────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────")
.append("├────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────")
.append(System.lineSeparator());
lines.lines().forEach(item -> {
sb.append("│ ").append(item.msg.contains("{}") ? String.format(item.msg.replace("{}", "%s"), item.args) : item.msg).append(System.lineSeparator());
});
sb.append("└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────");
sb.append("└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────");
LOGGER.info(sb.toString());
}

Expand Down

0 comments on commit c8c4535

Please sign in to comment.