Send AngularJS log messages and exceptions to your server side log. Log AJAX timeouts, errors and slow responses.
Author: 1974601? mperdeck

JavaScript logging and error handling for AngularJS

What it does

  • 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) { ... });

comments powered by Disqus
This page was last updated about 4 years ago.