1.0.3 • Published 5 years ago

@dillonstreator/litelogger v1.0.3

Weekly downloads
1
License
ISC
Repository
-
Last release
5 years ago

@dillonstreator/litelogger

0 dependency, super lightweight logging utility providing log levels, colors, and formatted JSON.

Installation

npm install @dillonstreator/litelogger

Usage

const logger = require('@dillonstreator/litelogger')();

logger.debug('debugging something...'); // process.env.DEBUG = true
logger.info('informative log here...');
logger.warn('warning... warning...');
logger.error('Error has occurred');

//outputs...

Basic Output

Config (optional)

propertytypevaluesdefaultdescription
prefixstringanynullinsert this string value after the output's date and before the log value (example below)
suppressTracebooleantrue/falsefalsespecifies whether or not the logger should output the stack trace of any Error object that is passed (example below)

Levels

levelcolordescription
debugmagentaprocess.env.DEBUG MUST be set to true for logging at this level
infocyann/a
warnyellown/a
errorredn/a

Usage cont.

prefixing

const prefixedLogger = require('@dillonstreator/litelogger')({prefix:'Ima Prefix'});

prefixedLogger.info('information with a prefix');

// outputs...

Prefixed Output


suppressTrace

const suppressedLogger = require('@dillonstreator/litelogger')({suppressTrace:true});
const nonSuppressedLogger = require('@dillonstreator/litelogger')();

const error = new Error('big failure!');

suppressedLogger.error(error);
nonSuppressedLogger.error(error);

// outputs...

Supressed Output


pretty printing

const logger = require('@dillonstreator/litelogger')();

logger.debug(
    'Thing one', { 'thing': 'one' },
    'Thing two', { 'works with': { 'nested': 'objects' } },
    'Thing three', { 'works with': { 'arrays': [1, 2, 3] } }
);

// outputs...

Object Output