0.3.3 • Published 9 years ago

snaplog v0.3.3

Weekly downloads
4
License
MIT
Repository
github
Last release
9 years ago

Snaplog

This small tool allow you to enhance your logs in console. Use differents levels of log, create a progress bar, deeply inspect your objects and enhance your errors.

NPM

ng-flat-datepicker screenshot

(Working progress) - only tested on nodejs 5.0 with ES6. I plan to convert in ES5 with Babel and so support older version of nodejs. Please, feel free to contribute.

Todo :

  • support ES5 with Babel
  • unit tests

Install

$ npm install snaplog --save

Usage

// Basic usage
var logger = require('snaplog');

// Set options to the logger
logger.config({}) // optional

// Log in console with differents levels
logger.success('We did it !');
logger.info('Roger that !');
logger.warn('Houston do you copy ??');
logger.error('Houston we have a problem !');
logger.emergency('Mayday Mayday Mayday !');
logger.inspect({we: {find: {the: {black: [{box: '!!!!'}]}}}});

// Create a progressbar
var progress = logger.progress({title: 'From Paris to New York', steps: 4});

setTimeout(nextCall, 1000, 'Roger that !');
setTimeout(nextCall, 3000, 'Houston we have a problem !');
setTimeout(nextCall, 5000, 'Mayday Mayday Mayday !');
setTimeout(nextCall, 7000, 'We did it !');

function nextCall(message) {
	progress.next({description: message});
}

Methods

.config(options) - This method allows you to set up the logger

  • (String) Object
logger.config({
	enabled: true, // toggle the logger
	time: {
		enabled: true, // toggle time display
		format: 'YYYY-MM-DD HH:mm:ss' // set time format
	},
	levels: { // levels settings
		success: {enabled: true, color: 'green'},
		info: {enabled: true, color: 'blue'},
		warn: {enabled: true, color: 'yellow'},
		error: {enabled: true, color: 'red'}
	}
}
  • .success(message) - print success log in terminal with colors
  • .info(message) - print info log in terminal with colors
  • .warn(message) - print warn log in terminal with colors
  • .error(message) - print error log in terminal with colors
  • .emergency(message) - print emergency log in terminal with colors

  • (String) message

logger.success('We did it !');
logger.info('Roger that !');
logger.warn('Houston do you copy ??');
logger.error('Houston we have a problem !');
logger.emergency('Mayday Mayday Mayday !');

.inspect(object, depth) - Deep inspection of an object

  • (String) message
  • (Number) depth
logger.inspect({ we: { find: { the: { black: [ { box: '!!!!'}]}}}});

Progress bar

.progress(options) - Instanciate a new progress bar

var progress = logger.progress({title: 'From Paris to New York', steps: 4});

progress.next(options) - Push the next step

progress.next({description: 'Roger that !'});

License: MIT

Author: Alexandre Da Costa

0.3.3

9 years ago

0.3.2

10 years ago

0.3.1

10 years ago

0.3.0

10 years ago

0.2.2

10 years ago

0.2.1

10 years ago

0.2.0

10 years ago

0.1.0

10 years ago

0.0.0

10 years ago