Skip to content
Angular 1 logging module supporing logz.io integration
Branch: master
Clone or download
Latest commit ad5c607 May 15, 2017
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
logging Initial commit May 15, 2017
LICENSE Initial commit May 15, 2017
README.md Initial commit May 15, 2017

README.md

angular1-logzio-logging

Angular 1 (currently using 1.3.20) logging module supporing logz.io integration

Introduction

This example module is a working module used in our application, but I haven't had time to "bowerize" it into a module. This should drop into an existing angular 1 application with minimal effort.

Pre-Requisites

  • stacktrace.js -- used to parse .map files and report source errors (currently using version 1.1.0)
  • ng-lodash -- used for the omit feature below (currently using verison 0.5.0)

Features

  • $log messages are batch posted based on buffering
  • Intercepts errors and reports as level:error messages

Disclaimer

This module is heavily stolen from various online blogs/examples, none of which I rememberd to include in my code. The core of my enhancement is the logzio.factory.js file, which is the magic that posts the data to logz.io. This factory may be lifted and inserted into your logging system to support logz.io.

Screenshot

The following is a real screenshot that was generated by an error in the application.

Angular Error

Setup

Enable the factory as follows:

logzioFactory.setConfig({
    api_key:          '**YOUR_LOGZIO_TOKEN**',
    enable_xhr:       true,
    enable_exception: true,
    log_level:        'info',
    source_prefix:    '../../../client/app/',
});

The above configuration:

  • Publishes all $log.info() messages to logz.in
  • All exceptions and xhr errors are reported
  • script.map file references our source code at "../../../client/app" (this is build-system specific, so your mileage may vary)

Configuration

The default configuration variable is:

api_key:                 null,
logzio_type:             "angular",
exception_logger_config: {
    windowInSeconds:        5,
    maxExceptionsPerWindow: 4, //max # of exceptions we log in the window interval
},
omit: [
    'config.data.password'
],
enable_xhr:              false,
enable_exception:        false,
log_logger_config:       {
    global: false,
    warn:   true,
    error:  true,
    info:   true,
    log:    false,
    debug:  false
},
baseMeta:                {},
delay_timing:            5000,
source_prefix:           '',

Notes:

  • windowInSeconds: Throttles errors to 5s. If multiple errors are generated within a 5s window, only the first 4 are reported (this prevents flooding logz.io).
  • delay_timing: This buffers messages for 5s and then posts to logz.io
  • omit: If you

To disable locally:

logzioFactory.setConfig({
    log_level: 'off'
});

Metadata for Searching

You may have some metadata information for your application (a JSON object) that you wish to include in each log message (for searching). Configure this meta information as follows (in your initialization routine):

var meta = {
    role: 'angular'
};
if ($rootScope.currentUser) {
    meta.username = $rootScope.currentUser.username;
    meta.env      = $rootScope.currentUser.node_env;
}
logzioFactory.setConfig({
    baseMeta: meta
});

LICENSE: MIT

You can’t perform that action at this time.