Nodejs在生产中调试错误 [英] Nodejs debug errors in production

查看:147
本文介绍了Nodejs在生产中调试错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在生产中运行的nodejs脚本



我不太可能(一次在一千次)获得这样的错误:



pre> TypeError:value在checkInt(buffer.js:1009:11)处于
之外
在Buffer.writeUInt16LE(buffer.js:1067: 5)
在Object.foo.bar(/fake/path/name.js:123:1);
在Object.foo.bar2(/fake/path/name2.js:123:1);
在Object.foo.bar3(/fake/path/name3.js:123:1);

导致生产服务器崩溃...



好,我有一个堆栈跟踪!但是我想知道每个通话或所有数据的当前数据是什么?



有什么好的工具或代码用于错误记录数据)生产代码?

解决方案

我强烈建议您使用 Winston Bunyan 。 npm软件包的选择是您应用程序的决定。



您可以通过浏览npm页面中的统计信息来对可用的npm软件包进行基准测试。统计资料基本上如下。


  1. 最后一天下载

  2. <上个月
  3. 下载

  4. 下载

  5. 开放的问题和开放拉动请求。

最近有更多的下载次数将表明有很大的支持你长期使用的模块。所以这很重要。



Winstan和Bunyan都是在市场上最好的登录npm软件包,主要的区别是,Winstan对于正常的日志记录来说真的很棒,灵活。当然,Winston提供了大量的记录功能。但是,为了利用这些能力,与Bunyan相比,需要做一些努力。



另一方面,Bunyan特别支持分析日志。所以基本上Bunyan是用于日志处理。所以如果你想分析你的日志,日志文件是强烈推荐使用Bunyan。 Bianyan对于Winstan来说,调整日志是相当容易的。



我对Bunyan和Winstan进行了彻底的比较。请查看下面的链接,以查看Winstan和Bunyan如何使用,具体取决于对Node应用程序的日志记录的范围,用例和必要性。
link: https://docs.google.com/document/d/1pD9PLyxlcHVxxOvserNLO9tAz-QA_Co-xo6cWLhLghc / edit?usp = sharing



同样在生产环境中,确保明智地使用日志记录级别。生产环境中大多数使用的记录级别是:




  • 错误

  • 信息

  • 调试


I have a nodejs script running in production

I unlikely (once in thousand times) get errors like this:

TypeError: value is out of bounds
    at checkInt (buffer.js:1009:11)
    at Buffer.writeUInt16LE (buffer.js:1067:5)
    at Object.foo.bar (/fake/path/name.js:123:1);
    at Object.foo.bar2 (/fake/path/name2.js:123:1);
    at Object.foo.bar3 (/fake/path/name3.js:123:1);

Causing the production server to crash...

Great I have a stacktrace! But I want to know what it's current data is for each call or all the data?

What are some great tools or code to use to for error logging(with it's current data) on production code?

解决方案

I highly recommend in using either Winston or Bunyan. The selection of npm package is a decision of your application.

You can benchmark the available npm packages by going through the stats in the available in npm pages. The stats are basically the following.

  1. downloads in the last day
  2. downloads in the last week
  3. downloads in the last month
  4. open issues and open pull requests.

Having higher number of downloads recently will indicate that there is a great support for the module you are using in the long run. So that is important.

Both Winstan and Bunyan being best logging npm packages in the market, the main difference is that, Winstan is really awesome and flexible for normal logging purposes. Of course Winstan offers a great deal of logging capabilities. But how ever, to make use of these capabilities, some effort need to put on compared to Bunyan.

Bunyan on the other hand is specially support the fact of "analysing logs". So basically Bunyan is for logs processing. So if you want to analyse your logs, log files it is highly recommend to use Bunyan. Tweaking logs with Bunyan is fairly easy vis-a-vis to Winstan.

I did a thorough comparison between Bunyan and Winstan. Please do check the link below to view how the Winstan and Bunyan can use depending on the scope, use-case and necessity of the logging to the Node application. link : https://docs.google.com/document/d/1pD9PLyxlcHVxxOvserNLO9tAz-QA_Co-xo6cWLhLghc/edit?usp=sharing

Also in the Production environment, make sure to use the logging levels wisely. The mostly used logging levels in production environment are:

  • error
  • info
  • debug

这篇关于Nodejs在生产中调试错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆