1.0.0 • Published 7 years ago

smalllog v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

smalllog

Smalllog is a simple console logging system for nodejs using colors and logging levels.

instalation

npm i -S smalllog

configuration

There is a few global parameters you can set:

namedefaultdescription
colorstrueuse color in console output
timefalseshow timestamp on output
level5threshold point to show messages
default'none'which message to show when you call directly

usage

example

You can use levels:

  • 0 - none, n
  • 1 - log, l
  • 2 - info, i
  • 3 - warn, w
  • 4 - error, err, e
  • 5 - debug, d
// initialize with default parameters
log = require('smalllog')('Worker')

// initialize with non defaults
log = require('smalllog')('AppName', {default: 'info'})

log.none('I have no level')
sub = 'substituition'
log.log('I´m using %s with objects: %o', sub, {key: 'value'});
log.info('message content', 2, 'string', {obj: true});
log.warn('an warning...');
val = 'of arguments'
log.l('message content', 'can', 'have', 'any number', val);
log.log('but will substitute only on first argument');
log.debug('so, I´ll fail', 'at using %s', 'substituition');

// if you call log directly it will default to the `option.default`
log('this will default to `info` due to use of options above!');

// unless its argument are an Error instance, in this case it will use error level
err = new Error('Oh crap!');
log(err);

// if you create another logger with another name then it´ll use another color

// if you create another logger with the SAME name it uses the same color

// colors are based on order of creation

log2 = require('smalllog')('API');
log3 = require('smalllog')('Database', {time: true}); // remember options are global...
log4 = require('smalllog')('HTTP');

// ... so all 3 entries bellow will have timestamps

log2('will be using another color!');
log3.w('will be using another color!');
log4.d('will be using another color too!');
1.0.0

7 years ago

0.1.1

7 years ago