Code Monkey home page Code Monkey logo

angular1-logzio-logging's Introduction

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

angular1-logzio-logging's People

Contributors

drmikecrowe avatar mike-zipit avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.