Best way to capture JavaScript errors in production? [closed]

拟墨画扇 提交于 2019-12-02 17:35:42

log4javascript's AjaxAppender can be used to send log messages to the server.

var log = log4javascript.getLogger("serverlog");
var ajaxAppender = new log4javascript.AjaxAppender("http://example.com/clientlogger");
log.addAppender(ajaxAppender);

You could put informational logging calls in your code and add a window.onerror handler to catch errors not caught by try/catch blocks in your code:

window.onerror = function(errorMsg, url, lineNumber) {
    log.fatal("Uncaught error " + errorMsg + " in " + url + ", line " + lineNumber);
};

You will also need to create something on the server to process the logging requests from the browser.

Full disclosure: I am the author of log4javascript.

detj
  1. Take a look at errorception

http://errorception.com/

  1. Also try Atatus - It is a new JavaScript Error Tracking Service along with Real User Monitoring (RUM) for modern web apps.

https://www.atatus.com/

  1. Also BugSense released an html5 version of their bug tracking

https://www.bugsense.com/docs/html5

So, you get a pretty interface to track them

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!