0.0.5 • Published 7 years ago

nomatic-logger v0.0.5

Weekly downloads
9
License
ISC
Repository
github
Last release
7 years ago

nomatic-logger

Build Status Coverage Status

Get serious about logging. This library takes the best concepts of winston and bunyan but diverges to create an extremely flexible yet elegant logging solution.

To create a logger:

const logger = require('nomatic-logger');

// logger.create(namespace: string)
const logger = logging.create('test');

Then, to use it:

// log[level](message: string[, data: Object])
log.info('This is a test message');
// with data:
log.info('This is a test message with data', {
  isTest: true
});

To listen for logging events on a namespace:

const logging = require('nomatic-logger');
logging.instance('test').on('info', (entry) => {
  /* `entry` is an object with `namespace`, `message`, `level`,
   * `hostname`, and `createdAt` fields.
   */
  console.log(`[${entry.level}]\t${entry.message}`);
});

The pattern works best in the following fashion:

  • Library developers create a namespaced Logger instance, and let their users know about it
  • Application developers subscribe to each instance and decide how they want to handle logging (i.e. display to console, send to a database, etc.). Application developers can also create their own namespaced instances for their own logging needs.

The mechanisms that "do" something with the log entries are called "Transports" (this is taken from winston). This functionality has not been implemented, but it will be very soon. For now, you can subscribe to a logger using the method in the last example above, as it will never go away.

This library is developed with TypeScript, and as such, includes definitions. However, you do not even need to know what TypeScript is to use this package. The compiled project is included in the npm package.