auth0/auth0-common-logging

Name: auth0-common-logging

Owner: Auth0

Description: Common utilities to write formatted logs in auth0 components

Created: 2016-04-06 12:24:53.0

Updated: 2018-03-06 02:34:58.0

Pushed: 2018-02-12 17:32:34.0

Homepage: null

Size: 49

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Common utilities to write formatted logs in auth0 components.

Installation
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.

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

tLogger.watch(process);
tLogger.watch(httpServer);
process event logger

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

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:

tLogger.watch(process);

exit = function (exitCode) {
turn function () { process.exit(exitCode); };


ess.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:

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:

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

my_serializers = _.extend({}, serializers, {
r: 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;



an.createLogger({ ..., serializers: my_serializers });
Common Streams used for logs
HttpWritableStream = require('auth0-common-logging').Streams.HttpWritableStream;
httpWritableStream = new HttpWritableStream('http://url');

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.