Code Monkey home page Code Monkey logo

auth0-common-logging's Introduction

Common utilities to write formatted logs in auth0 components.

Installation

npm i auth0/auth0-common-logging --save

EventLogger

The watcher is a common abstraction that can subscribe to events of different node.js instances and write logs in a predefined logger.

var EventLogger = require('auth0-common-logging').EventLogger
var eventLogger = new EventLogger(bunyanLogger);

eventLogger.watch(process);
eventLogger.watch(httpServer);

process event logger

The process event logger emits a log entry for the following events of a node.js process instance:

  • exit signals events: SIGTERM, SIGINT
  • uncaughtException

In addition to these 3 events it emits and "starting" log entry inmediatelly when is called.

Please note, that subscribing to the afore mentioned events normally changes the behavior of node.js, this means that the process will not longer exit by itself, you need to subscribe and exit. Example:

eventLogger.watch(process);

var exit = function (exitCode) {
  return function () { process.exit(exitCode); };
}

process.on('SIGTERM', exit(0))
       .on('SIGINT', exit(0))
       .on('uncaughtException', function () {
          //give some time to write the log.
          setTimeout(function () {
            exit(1);
          }, 200);
       });

http event logger

The http event logger log entries for the following events of a node.js process instance:

  • listening

Serializers

auth0-common-logging export a Serializers object for bunyan. The serializer includes: req, res and err with our defaults.

Serializers can be extended as follows:

var _ = require('lodash');
var serializers = require('auth0-common-logging').Serializers;

var my_serializers = _.extend({}, serializers, {
  err: function (err) {
    //run the common-loggin serializer:
    var result = serializers.err(err);
    //append some data
    if (err.inner) {
      result.inner = this.err(err.inner);
    }
    //return
    return result;
  }
});

bunyan.createLogger({ ..., serializers: my_serializers });

Common Streams used for logs

var HttpWritableStream = require('auth0-common-logging').Streams.HttpWritableStream;
var httpWritableStream = new HttpWritableStream('http://url');

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.