Experimenting with window.onerror, trying to make JavaScript debugging easy.

What does it do?

Provides JavaScript error details in a readable format. You can log these errors remotely by enabling remoteLogging. After enabling, logerr will send a post request to the desired action/url with exception details along with custom parameters (if provided using additionalParams).

Example

Lets take a simple code snippet which will raise an exception.

var test = a + 1; //a is not defined

Instead of javascript throwing Uncaught ReferenceError: a is not defined, using logerr will output something like

Type: error Error: Uncaught ReferenceError: a is not defined StackTrace: ReferenceError: a is not defined at http://localhost:8888/logerr/logerr.min.js:3:12 File Name: logerr.js Path: http://localhost:8888/logerr/logerr.js Line: 51 Column: 12 Date: Tue Jun 28 2016 19:51:22 GMT+0530 (IST) Debug: http://localhost:8888/logerr/logerr.js:51 Get Help: https://stackoverflow.com/search?q=Uncaught+ReferenceError:+a+is+not+defined

Install

Just include logerr.js file in the <head> section of your page, before you include any other JavaScript. To initialize logerr, use Logerr.init()

<!DOCTYPE html> <html lang="en"> <head> <script src="logerr.js"></script> <script> Logerr.init(); </script> </head> <body> Am fancy </body> </html>

Enable Remote Logging

Make sure you have CORS enabled if logging cross-domain.
Logerr.init({ remoteLogging: true, remoteSettings: { url: 'REMOTE_URL', additionalParams: { logged_by: 'Sam' }, successCallback: function () { console.log('Im logged.'); }, errorCallback: function () { console.log('Err! Something went wrong.'); } } });

Check out logerr-remote for logging exceptions remotely.


Default Configuration & Datatypes

detailedErrors: true //Boolean true/false, Optional remoteLogging: false //Boolean true/false, Optional remoteSettings: { //Object {}, required if remoteLogging is set to true url: null, //String '', required if remoteLogging is set to true additionalParams: null, //Object {}, optional successCallback: null, //function() {}, optional errorCallback: null //function() {}, optional }