bunyan_Bunyan日志记录中的生产故障排除

bunyan

I’ve been providing technical support 24/7 for most of the Node.js services I’ve worked on for quite some years now. During this time I’ve found myself many times wearing a detective hat, digging into thousands of log lines, when no other resource was available to help to troubleshoot an issue. Of course, in an ideal world, you have illuminating metrics, thorough crash reporting tools, and other similar allies to help you find the root cause of the troubles. In reality, log files are sometimes our last resort to find the culprit. I’d like to share some of the principles I’m sticking to in order to produce logs that will help me catch the error smoothly and as soon as possible.

我已经为我工作了很多年的大多数Node.js服务提供了24/7的技术支持。 在这段时间里,我发现自己无数次戴着侦探帽,挖掘了成千上万条日志,而没有其他资源可用来解决问题。 当然,在理想的情况下,您将具有启发性的指标,完善的崩溃报告工具以及其他类似的盟友,可以帮助您找到问题的根本原因。 实际上,日志文件有时是我们找到罪魁祸首的最后手段。 我想分享一些我坚持的原则,以便生成日志,以帮助我顺利,尽快地发现错误。

了解功能的签名 (Know the signature of the functions)

It’s good to double-check the log method API of Bunyan. I’ve seen many occurrences of logs where the message is passed in the wrong argument of the function, which leads to a less readable output.

最好仔细检查Bunyan的日志方法API 。 我已经看到许多日志记录,其中消息是通过函数的错误参数传递的,这导致输出的可读性较差。

If we run the code above, you can see how the first log line outputs more sensible and readable data than the second:

如果我们运行上面的代码,则可以看到第一行日志比第二行输出更明智和可读的数据:

Image for post

The first log line has a msg property with value Something went wrong, as opposed to the second log line, whose msg contains an amalgam that mixes the message with the error stack trace. Should you have a log visualization tool like Kibana or Splunk, the first log line will be easier to search for if you perform a pseudo-query similar to msg="Something went wrong".

与第二条日志行相反,第二条日志行的msg包含将消息与错误堆栈跟踪信息混合在一起的汞齐,第一条日志行的msg属性值为Something went wrong了。 如果您具有像Kibana或Splunk这样的日志可视化工具,则如果执行类似于msg="Something went wrong"的伪查询,则第一条日志行将更易于搜索。

Moreover, this approach will allow you to benefit from bunyan’s CLI filtering capabilities. More about that later on.

此外,这种方法将使您受益于bunyan的CLI过滤功能。 稍后会更多。

首先是字段,然后是日志消息 (First the fields, then the log message)

An object literal can be passed to the bunyan log methods, but make sure this object is the first argument, and the second one is the log message. The output will not be so nice if you do it the other way around.

可以将对象文字传递给bunyan log方法,但请确保该对象是第一个参数, 第二个是日志消息。 如果您反过来做,输出将不会很好。

As you can see in the screenshot below, the first log line looks much better than the second.

正如您在下面的屏幕快照中看到的那样,第一

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值