pretty-debug

A highly configurable & lightweight debug library that prints debug messages beautifully. It works in Node.js and Web browser environments with very low memory footprint.

Members

static color :Object.<string>

Different ANSI color to decorate different segments

Properties:
Name Type Description
reset string

Text Color Reset

black string

Text Color Block

red string

Text Color Red

green string

Text Color Green

yellow string

Text Color Yellow

blue string

Text Color Blue

magenta string

Text Color Magenta

cyan string

Text Color Cyan

white string

Text Color Cyan

bgBlack string

Background Color Black

bgRed string

Background Color Red

bgGreen string

Background Color Green

bgYellow string

Background Color Yellow

bgBlue string

Background Color Blue

bgMagenta string

Background Color Magenta

bgCyan string

Background Color Cyan

bgWhite string

Background Color White

Methods

static alert(…var_args)

Prints alert messages in level 4

Parameters:
Name Type Attributes Description
var_args * <repeatable>

Variadic Argument

Examples
debug.alert("An alert message!");
const birthTimestamp = { date : "15/12/1993", time : "12:05 AM" };
debug.alert(birthTimestamp);

static attachStream(stream)

Attaches stream to pipe debug output

Parameters:
Name Type Description
stream Object.<stream>

Stream to attach

static critical(…var_args)

Prints critical messages in level 1

Parameters:
Name Type Attributes Description
var_args * <repeatable>

Variadic Argument

Examples
debug.critical("API server critical error");
const criticalMessage = { message : "Some Critical Error" };
debug.critical(criticalMessage);

static detachStream(stream)

Detaches stream from debug output

Parameters:
Name Type Description
stream Object.<stream>

Stream to detach

static error(…var_args)

Prints error messages in level 2

Parameters:
Name Type Attributes Description
var_args * <repeatable>

Variadic Argument

Examples
debug.error("Error in recording server");
const errorMessage = { message : "Some Error", errorCode : 4 };
debug.error(errorMessage);

static generatePolicy(lowerLimit, upperLimit) → {Object.<policy>}

Generates policy for different memory monitors

Parameters:
Name Type Description
lowerLimit number

Lower limit

upperLimit number

Upper limit

Returns:
Object.<policy>

static info(…var_args)

Prints info messages in level 5

Parameters:
Name Type Attributes Description
var_args * <repeatable>

Variadic Argument

Examples
debug.info("Here is an info message.");
const birthTimestamp = { date : "15/12/1993", time : "12:05 AM" };
debug.info(birthTimestamp);

static log(…var_args)

Prints log messages in level 6

Parameters:
Name Type Attributes Description
var_args * <repeatable>

Variadic Argument

Examples
debug.log("Just a simple log message");
const policy = { upperLimit : 70, lowerLimit : 20 };
debug.log(policy);

static memoryWatermark()

Prints highest RAM usage in application. Scheduled healthcheck is needed to set watermark.

Example
memoryWatermark();

static nodeMemoryMonitor(stream, callback)

Prints RAM usage by Node.js

Parameters:
Name Type Description
stream Object.<stream>

Stream Object

callback function

Callback function to invoke when alarm triggers

Example
debug.nodeMemoryMonitor({
		heapTotal: { upperLimit : 100 }
	}, function(){
		debug.critical('Memory Usage Alarm : Total heap usage is above 100 MB');
	}
);

static scheduleHealthCheck(inputFunc, timeInMinutes)

Set Schedule to perform healthcheck

Parameters:
Name Type Description
inputFunc function

Healthcheck function

timeInMinutes numbers

Interval in minutes

Example
debug.scheduleHealthCheck(function(){
	debug.memoryWatermark();
	debug.sysMemoryMonitor();
	debug.nodeMemoryMonitor({
		heapTotal: { upperLimit : 5 }
	}, function(){
		debug.critical('Memory Usage Alarm : Total heap usage is above 5 MB');
	});
}, 10);

static setOptions(userOptions)

Overwrites default options and debug text formats

Parameters:
Name Type Description
userOptions Object.<userOptions>

Options User specific options

static sysMemoryMonitor(alarmPolicy, callback)

Prints RAM usage by operating system

Parameters:
Name Type Description
alarmPolicy Object.<alarmPolicy>

Policy object to trigger alarm

callback function

Callback function to invoke when alarm triggers

Example
debug.sysMemoryMonitor({
		MemTotal: { upperLimit : 700 }
	}, function(){
		debug.critical('Memory Usage Alarm : Total system memory usage is above 700 MB');
	}
);

static warn(…var_args)

Prints warn messages in level 3

Parameters:
Name Type Attributes Description
var_args * <repeatable>

Variadic Argument

Examples
debug.warn("This is your last warning.");
const resource = { RAM : 10, CPU : 60 };
debug.warn(resource);