0. How To Use

Install

$ npm install pretty-debug

Usage

Pretty Debug exposes a debug object. Just attach any stream you want to the module to pipe debug messages. process.stdout is the default steam which prints output to console. Any other streams like TCP socket or request to an HTTP server can be attached on runtime to pipe the debug output.

Basic usage

  • Create debug instance :

    const debug = require('pretty-debug');
    
  • Set options :

    debug.setOptions({ 
    	enable: true,		// Turning on debug print
    	enableColor: true,	// Enabling color output
    	enableGC: true,		// Enabling autometic gerbage collection
    	debugLevel: 6, 		// Setting debug level 6 (Upto INFO)
    	}  
    });
    
  • Attach stream :

    debug.attachStream(sock); 	// Attaching new stream to serve debug messages
    
  • Detach stream :

    debug.detachStream(sock); 	// Detaching stream
    
  • Set options :

    debug.setOptions({ 
    	enable: true,		// Turning on debug print
    	enableColor: true,	// Enabling color output
    	enableGC: true,		// Enabling autometic gerbage collection
    	debugLevel: 6, 		// Setting debug level 6 (Upto INFO)
    	}  
    });
    
  • Print in different debug levels :

    debug.log('The quick brown fox jumps over the lazy dog');
    debug.info('The quick brown fox jumps over the lazy dog');
    debug.alert('The quick brown fox jumps over the lazy dog');
    debug.warn('The quick brown fox jumps over the lazy dog');
    debug.error('The quick brown fox jumps over the lazy dog');
    debug.critical('The quick brown fox jumps over the lazy dog');
    
  • Show highest RAM usage :

    debug.memoryWatermark();
    
  • Show memory used by OS :

    debug.sysMemoryMonitor();
    
  • Show memory used by Node.js :

    debug.nodeMemoryMonitor(();
    
  • Set alarm policy for RAM usage :

    debug.nodeMemoryMonitor({
    	heapTotal: { upperLimit : 5 }
    }, function(){
    	debug.critical('Memory Usage Alarm : Total heap usage is above 5 MB');
    	// Do other things like send email!
    });
    

Run Examples

To run the examples given in the repository, go to the root folder of the library and run the command given below. Replace "Target_Example.js" with desired example's file name.

$ node Examples/Target_Example.js

-----------------------------------------------------