在一行中记录多个内容是否比记录多行内容有任何优势?

huangapple go评论76阅读模式
英文:

Any advantage of logging multiple things in one line rather than logging multiple lines?

问题

有这样写的任何优势吗:

logger.info("[Request]: {}, [Response]: {}", requestObject, responseObject);

而不是像这样写:

logger.info("[Response]: {}", responseObject);```

<details>
<summary>英文:</summary>

Is there any advantage of writing like this:

logger.info("[Request]: {}, [Response]: {}", requestObject, responseObject);


rather writing like: 

logger.info("[Request]: {}", requestObject);
logger.info("[Response]: {}", responseObject);


</details>


# 答案1
**得分**: 1

一个重要优点是能够搜索发生的事情(例如,使用 `grep`),并能够在结果中获取所有相关信息,而不必打开文件,搜索所需内容(例如,请求的某些属性),然后再向下滚动以查看相关信息(在此示例中 - 响应详情)。

<details>
<summary>英文:</summary>

One big advantage is being able to search for things that happened (e.g., with `grep`) and being able to get all the relevant info in the results, instead of having to open the file, search for whatever you want (e.g, some property of the request) and then having to scroll down to see the related info (in this example - the response details).

</details>



# 答案2
**得分**: 1

在多线程环境中工作时,

- 单行日志记录:**在一组中轻松查看相关内容**
- 多行日志记录:**下一行和上一行可能无关**

<details>
<summary>英文:</summary>

Let&#39;s say you&#39;re working in a multiple-threads context. 

 - One-line logging: **Easy to see the related things in a group**
 - Multiple-lines logging: **The next line and the previous line might be not relevant**

</details>



# 答案3
**得分**: 1

在多行和两个并行请求的情况下,您无法确定哪个[Response]对应哪个[Request]。您需要一种类似于requestId的附加字段来关联它们(这在任何情况下都非常有用)。

<details>
<summary>英文:</summary>

In case of multiple lines and two parallel request you couldn&#39;t say which [Response] belongs to which [Request]. You would need some kind of an additional field like requestId to correlate them (which is quite useful anyways). 

</details>



huangapple
  • 本文由 发表于 2020年9月4日 16:42:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/63737748.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定