Skip to content

inakianduaga/angular-remote-logger

Repository files navigation

angular-remote-logger

Build Status Coverage Status Code Climate Dependency Status Dev Dependency Status Bower version

Angular Exception/failed XHR call/$log remote logger

Installation

Bower

  • Add angular-remote-logger as a bower dependency (with the desired version).
  • Reference angular-remote-logger.min.js file (or better yet, use a bower script injector such as main-bower-files for grunt/gulp to automatically add the dependency)

Manually

Copy the file angular dist/angular-remote-logger.min.js into your project and reference it in your app.

Usage

Add the angular module angular-remote-logger as a dependency to your app. For example:

angular.module('myApp', ['angular-remote-logger', ...]);

This will:

  • register an httpInterceptor to log all failed xhr requests
  • register a decorator for the $exceptionHandler provider to log all app exceptions.

Exception logger

Log all application exceptions remotely, with a configurable throttle interval.

Configuration

The parameters can be modified by changing the values of the constant EXCEPTION_LOGGER_CONFIG, as follows

angular.module('angular-remote-logger')
  .config(
    function (EXCEPTION_LOGGER_CONFIG) {
      EXCEPTION_LOGGER_CONFIG.windowInSeconds = 5; //defines the window interval for the throttle checking
      EXCEPTION_LOGGER_CONFIG.maxExceptionsPerWindow = 4; //how many exceptions per window are logged before throttling
      EXCEPTION_LOGGER_CONFIG.remoteLogUrl = 'exception/Logger/Config/Remote/Url'; //remote log endpoint
      EXCEPTION_LOGGER_CONFIG.enabled = false; //disables the exception logger
    }
  );

Remote Payload

The remote logger will POST the exception message & cause

data : {
  exception : exception,
  cause : cause
}

Http Xhr error logger

Log all non-200 xhr responses remotely

Configuration

The parameters can be modified by changing the values of the constant XHR_LOGGER_CONFIG, as follows

angular.module('angular-remote-logger')
  .config(
    function (XHR_LOGGER_CONFIG) {
      XHR_LOGGER_CONFIG.remoteLogUrl = 'xhr/Logger/Config/Remote/Url'; //remote log endpoint
      XHR_LOGGER_CONFIG.enabled = false; //disables the xhr-logger
    }
  );

Remote Payload

The remote logger will POST the entire xhr rejection json object

data: rejection

Log logger

Log all $log call messages remotely

Configuration

The parameters can be modified by changing the values of the constant LOG_LOGGER_CONFIG, as follows

angular.module('angular-remote-logger')
  .config(
    function (LOG_LOGGER_CONFIG) {
      LOG_LOGGER_CONFIG.remoteLogUrl = 'log/Logger/Config/Remote/Url'; //remote log endpoint
      LOG_LOGGER_CONFIG.enabled = {
        global: true, //global flag to disable remote logging for all log operations 
        warn : true, //toggle logging for individual log operations.
        error : true,
        info : true,
        log : true,
        debug : true
      }
    }
  );

Remote Payload

The remote logger will POST the log message, along with the log type:

data:   {
  message: message,
  logType: logType // info/log/debug/error/warn
}

Contributing

Setup Environment

  1. Install node.js, npm for package management
  2. Install bower globally.
  3. Run npm install, bower install to install the build/app dependencies

Tasks

  • Run gulp from the root installation folder to retrieve a list of the available tasks