JSNLog.AngularJS

JavaScript logging and error handling for AngularJS

Added by: Sam Deering

GitHub

Repository

mperdeck/jsnlog.angularjs

Stats

Stars: 25

Watchers: 25

Forks: 7

Author

Mperdeck
Mperdeck

Module Description

Logging and JavaScript error handling for AngularJS

logToServer.js

  • Replaces standard AngularJS $log to version that logs to the server, and optionally to the console using a consoleAppender.
  • Replaces AngularJS $exceptionHandler with version that logs JavaScript exceptions to the server.
  • Provides Interceptors to log AJAX errors and timeouts to the server, and to log warning messages when AJAX responses are slow.

How to use

Install the JSNLog JavaScript Logging Package. Copy logToServer.js to your site and load it into your pages, such as with a script tag.

To use the new $log and $exceptionHandler, simply import module logToServer into your main module, like so:

var app = angular.module('mainmodule', ['logToServer']);

To use the interceptors, add them to the interceptors array for your application:

app.config(['$httpProvider', function($httpProvider) {
    $httpProvider.interceptors.push('logToServerInterceptor');
}]);

When you call $http to send an AJAX message, set the timeout and the delay after which a warning log message is sent in milliseconds in the config object, using timeout and warningAfter:

$http({ method: '...', url: '...', data: ..., timeout: 5000, warningAfter: 2000 })
.success(function (data, status, headers, config) {
    ...
})
.error(function (data, status, headers, config) {
    ...
});

More about AngularJS Error Handling

Module stats last updated: 2017-09-20 15:00:08

Disclaimer: Some data on this page may have been gathered from the authors GitHub respository. If you see any mistakes or outdated information please let us know. Thanks!