简体   繁体   English

记录Javascript / Jquery错误和异常

[英]Logging Javascript / Jquery errors and Exceptions

One thing I notice i javascript / jquery web architectures is that it seems very easy for exceptions to get swallowed and go unnoticed. 我注意到我的javascript / jquery网络体系结构的一件事是,异常容易被吞没并且不被注意似乎很容易。 I'm thinking what would be really good is if anytime your web tier had a javascript exception, information about it was sent on a AJAX request back to your server so at least you could log information about it. 我在想,如果您的Web层上任何时候出现javascript异常,有关它的信息都是通过AJAX请求发送回您的服务器的,那么至少您可以记录有关它的信息,那将是真正的好。

I am wondering there has to be some framework feature that already does this as I think it would be a really useful feature. 我想知道已经有一些框架功能已经做到了,因为我认为这将是一个非常有用的功能。 Anyone know of any framework, feature or library that will do this? 任何人都知道将执行此操作的任何框架,功能或库吗?

Thanks 谢谢

There probably are, but it isn't hard to implement yourself. 可能有,但是实现自己并不难。 Just hook an event handler to window for the error event, and make the AJAX request there. 只需将事件处理程序挂接到error事件的window ,然后在此处发出AJAX请求即可。

Arguments that will be passed to your event handler, in order, are: the error message as a string, the URL where the error was raised, also a string, the line number where the error was raised, followed finally by the event object. 按顺序将传递给事件处理程序的参数为:错误消息作为字符串,引发错误的URL,也是字符串,引发错误的行号,最后是事件对象。

You have to tak a lot of things into account when building your own solution. 构建自己的解决方案时,您必须考虑很多事情。 For example you will see a lot of noise generated by JavaScript errors in plugins, 10-20% of all errors logged. 例如,您会在插件中看到JavaScript错误产生的大量噪音,占记录的所有错误的10-20%。 Grouping the errors intelligently is an extremely hard problem, because of the very different error messages you get for different browsers and versions. 智能地对错误进行分组是一个非常困难的问题,因为对于不同的浏览器和版本,您会收到非常不同的错误消息。 Also you don't want to log 1,000 errors pr user if you have an error in a mousemove event. 另外,如果mousemove事件中有错误,您也不想登录1000个错误。 And there is a ton of other stuff to consider. 还有很多其他的东西要考虑。

We've build a SaaS solution like the one you ask for Muscula . 我们已经构建了一种SaaS解决方案,就像您要求Muscula的解决方案一样。 We're in private beta at the moment, but working very hard to release. 目前,我们处于私人Beta版,但要努力发布。 We've already monitored more than 100 million pageviews for JavaScript errors, and we log more than 1 million JavaScript errors a week. 我们已经监视了超过1亿次综合浏览量的JavaScript错误,并且每周记录超过100万个JavaScript错误。 And beyound the issues I mention above we also have tackled the problem of displaying errors in minified JavaScript as pretty printed, integration with Goggle Analytics and much much more. 避免了我上面提到的问题,我们还解决了在精巧的JavaScript中显示错误并显示错误,与Goggle Analytics集成等问题。

You install Muscula like Google Analytics, just copy a script to your page, and you are logging JavaScript errors. 您像安装Google Analytics(分析)一样安装Muscula,只需将脚本复制到您的页面上,就可以记录JavaScript错误。

You can make your own, but it can be a bit tricky because you can get flooded with errors, and sending many ajax requests can compound the problem. 您可以自己创建,但可能会有些棘手,因为您可能会充斥错误,并且发送许多ajax请求会使问题更加复杂。 Error logging must be debounced, and god forbid your error tracking code produces and error on some obscure browser. 错误日志记录必须消除抖动,上帝禁止您的错误跟踪代码在某些晦涩的浏览器上产生并出现错误。 There are a couple of SaaS products with free plans that are worth looking at: 有一些带有免费计划的SaaS产品值得关注:

http://errorception.com/ http://errorception.com/

http://www.exceptionhub.com/ http://www.exceptionhub.com/

I would try those, and then if they don't suite your needs, then you can roll you own. 我会尝试这些,然后,如果它们不能满足您的需求,那么您可以自己决定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM