ndeed

Event-based logging for node.js and the browser.

Usage no npm install needed!

<script type="module">
  import ndeed from 'https://cdn.skypack.dev/ndeed';
</script>

README

ndeed

Event-based logging for node.js and the browser.

About

This package provides a lightweight and unique approach to instrumenting debug and trace logging into your package modules and applications. Rather than hard coding a dependency on any of the popular event logging libraries directly into your code, ndeed provides a logging capability that formats logs into JSON objects, and emits events.

What you do with the event information is up to you! Develop your own procedures to write log information to the console or other targets, or integrate with another logging library to manage the actual output stream.

Install

Install from the NPM repository, or directly from GitLab:

npm install ndeed
npm install gitlab:arsnebula/ndeed

Usage

The library is divided into two core classes. The base nDeed class provides utility functions that can transform an arguments list into a JSON object, and emit log events. Static metadata can be added and updated that is added to all logged events. Logging can be enabled or disabled. A getLogger factory method is used to create new Logger instance.

A Logger instance is what you should use for logging information. It provides the standard methods for logging debug, info, warning, error and fatal events. Static metadata can also be added and updated on a logger and will be added to all logged events for that specific logger instance. Logging can be enabled or disabled on each logger instance seperately.

Ok, let's see some code!

// import the class
const nDeed = require( 'ndeed' )

// create an instance providing any static metadata
// you want added to all logs
const ndeed = new nDeed( {'app': 'myApp'} )

// metadata can be updated anytime
ndeed.meta = {'app': 'myApp', 'version': '1.0.0'}

// enable or disable all logging (defaults to true)
// if false, logging is disabled for all loggers
ndeed.enabled = true

// listen for the log event and do what you want with it
// any message filtering can be done here
ndeed.on('log', ( item ) => {
  console.log( item )
})

// errors will never be thrown by the library, but if error
// occurs you can listen for the error event
ndeed.on('error', ( error ) => {
  console.error( error )
})

// create a logger for a specific module providing any metadata
// you want added to any logs created with this logger
const logger = ndeed.getLogger( {'module': 'myModule'} )

// logger metadata can be updated anytime
logger.meta = {'module': 'myModule', 'ver': '0.1.2'}

// enable or disable logging for a logger (default is true)
// if false, logging is disabled only for this logger
logger.enabled = true

// call the debug, info, warning, error or fatal logging methods
logger.debug('time to get more coffee')
logger.info('some info')
logger.warning('do not run with scissors')
logger.error('the earth does not revolve around the sun')
logger.fatal('bang, bang - you got me')

Issues, Enhancements and Contributions

Feedback is welcome and appreciated. Issues or enhancement requests can be submitted using the Issues List on GitLab. For code contributions, please see our Contributing Guide.

Dependencies and Attributions

License

MIT - Copyright (c) 2016 Ars Nebula