Angular Exception/failed XHR call/$log remote logger
- 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 asmain-bower-files
for grunt/gulp to automatically add the dependency)
Copy the file angular dist/angular-remote-logger.min.js
into your project and reference it in your app.
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.
Log all application exceptions remotely, with a configurable throttle interval.
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
}
);
The remote logger will POST the exception message & cause
data : {
exception : exception,
cause : cause
}
Log all non-200 xhr responses remotely
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
}
);
The remote logger will POST the entire xhr rejection json object
data: rejection
Log all $log call messages remotely
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
}
}
);
The remote logger will POST the log message, along with the log type:
data: {
message: message,
logType: logType // info/log/debug/error/warn
}
- Install
node.js
,npm
for package management - Install
bower
globally. - Run
npm install
,bower install
to install the build/app dependencies
- Run
gulp
from the root installation folder to retrieve a list of the available tasks