Common utilities to write formatted logs in auth0 components
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Common utilities to write formatted logs in auth0 components.


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


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);;;

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:;

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 () {
          }, 200);

http event logger

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

  • listening


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 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');