bobble

0.1.1 • Public • Published

bobble

Yet another node.js logger

Build Status Dependencies by David Built with Grunt

Module Overview

bobble is a simple to use logging module. It can log to console, or a file and can also have custom log levels added that can be configured to log to different files.

Usage

In its simplest form, create an instance of bobble and call the log function to write to the console. Each logged line will be preceded with a timestamp, which is in UK format (DD-MM-YYYY HH:mm:ss.SSS) by default.

var bobble = require('bobble');
var logger = new bobble();
 
logger.log("Log this to console");

To change bobble's default behavior, pass in a configuration object when creating the new instance. For example, in order to change the timestamp date format, pass a 'dateFormat' parameter specifying the date format to use. bobble uses Moment.js to format its timestamps, so any format that is supported by Moment.js is also supported by bobble.

var bobble = require('bobble');
var logger = new bobble(
{
  'dateFormat' : 'MM-DD-YYYY HH:mm:ss.SSS'
});
 
logger.log("Log this to console");

In order to write output to a file instead of the console, pass a 'fileName' configuration parameter specifying the file to log to.

var bobble = require('bobble');
var logger = new bobble(
{
  'fileName' : 'mylog.log'
});
 
logger.log("Log this to mylog.log");

Custom Log Levels

To add custom logging levels to bobble, pass in an object with the log levels as the keys, followed by an object containing an optional file name to log to. The new log levels are added to bobble as functions and can be called instead of the log() method.

var bobble = require('bobble');
var logger = new bobble(
{
  'fileName' : 'default.log',
  'logLevels' :
  {
   'warn' : { 'fileName' : 'warnings.log' },
    'error' : { 'fileName' : 'errors.log' },
    'info' : {}
  }
});
 
logger.warn("This is a warning logged to my warnings.log file");
logger.error("This is an error logged to my errors.log file");
logger.log("This will continue to be logged to default.log");
logger.info("This will also be logged to default.log");

Logging Object Properties

Custom log levels can also be used to output the properties of a passed object in a custom format. Pass the objectMapping parameter during the setup of a log level, then pass the object to log when calling the log level function:

var http = require('http');
var bobble = require('bobble');
var logger = new bobble(
{
  'fileName' : 'default.log',
  'logLevels' :
  {
   'warn' : { 'fileName' : 'warnings.log' },
    'web' : { 
      'fileName' : 'web.log', 
      'objectMapping' : ['method', 'url'] 
    },
    'info' : {}
  }
});
 
var server = http.createServer(function(req, res){ 
    logger.log('Log req details to the web log.');
    logger.web(req);
}.listen(3000);

Readme

Keywords

Package Sidebar

Install

npm i bobble

Weekly Downloads

0

Version

0.1.1

License

LGPL v3

Last publish

Collaborators

  • tophatsteve