1.0.1 • Published 8 years ago

logor v1.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

logor

© 2016, Onur Yıldırım (@onury). MIT License.

Simple logging utility with levels, for Node.js.
This also brings some nice formatting, colors and JSON capabilities to your logs.
npm i logor

Usage

var log = require('logor').config({
    level: 2, // log.Level.INFO
    colors: true,
    format: '{DATE} {TIME}  {LEVEL}\t{*}'
});

log.info('Output colorful logs with date/time and level info.');

Output Example

Example Screenshot

Log Levels and Methods

Configuration

Pass an options object to log.config() method, with the following properties:

Set all options at once:

log.config({
    level: 2,
    colors: true,
    format: '{*}'
});

Set log level:

log.level = 2;
// When you set level to `2` (`INFO`),
// levels with greater values will not output any logs.
log.debug('This will not be logged.');

Enable/disable all colors:

log.colors = false;
log.info('Log without colors');
// —> Log without colors

Formatting Output

{} around a placeholder indicates that colors should be applied for that component. e.g. magenta if this is a debug log. Use () instead, to gray-out that component; or [] for no colors.

{color} » (gray) » [none]

Logs with date/time:

log.format = '{DATE} {TIME}\t{*}';
log.info('Log with full date/time');
// —> 2016-08-18 15:30:43   Log with full date/time

Logs with level info:

log.format = '{TIME}\t{LEVEL}\t{*}';
log.info('Log with time and level');
// —> 15:30:43   INFO    Log with time and level
log.format = '(TIME)\t{LEVEL}\t[*]';
log.info('This is the default color of the console.');
// —> 15:30:43   INFO   This is the default color of the console.

JSON Logs

Use log.json() to output a log with stringified argument(s).
Use log.jsonf() to also format with indents.
Use log.s() to stringify an individual or multiple values.
Use log.sf() to also format with indents.

This also handles circular references.

log.json({ info: 'this is an object' });
log.jsonf({ jsonf: 'this is a formatted json.' });
log.error(log.s({ 'stringify-arg': 'log.error(log.s(object))' }));
log.warn(log.sf({ 'stringify-format': 'log.warn(log.sf(object))' }));

Change-Log

v1.0.1 (2016-09-05)

  • Return self from .config() method.

v1.0.0 (2016-08-20)

  • initial release.

License

MIT.