1.1.4 • Published 7 years ago
debugmessage v1.1.4
Description
debugmessage is a simple module for node.js that provides utility to write colored command line in debug nodejs script
Requirements
- node.js -- v0.8.0 or newer
Install
npm install debugmessage
Examples
- simple base method to write cmd message colored (es6)
import {DebugMessage} from "debugmessage";
let log=new DebugMessage();
log.debug("this is only a debug");
log.command("this is only a command");
log.error("this is a error");
write on console
[DEBUG] this is only a debug
[COMMAND] this is only a command
[ERROR] this is only a error
DEBUG is a cyan foreground color COMMAND is a yellow foreground color ERROR is a red foreground color
description
module debugmessage use ansi colors to colorize the console log label on squares. Each color is a single method write it in lowercase
Foreground colors
- black
- red
green
yellow
blue
magenta
cyan
white
Background colors
bgblack
bgred
bggreen
bgyellow
bgblue
bgmagenta
bgcyan
bgwhite
import {DebugMessage} from "debugmessage";
let log=new Message();
let green=log.green("message green");
console.log(green);//normal console but colored
//or you can print with module
log.printMessage("message","green");
//use background color green
log.printMessage("message","bggreen");
//-------------------------
// simple test
log.test();
npm run test (grunt run:test)
API
Events
Property
- print< boolean >: show/hide message in commandline
Methods
- (constructor)() - Creates the dynamic sequences colors method.
- addLabel(labelstring:string,color:string):string
- DESCRIPTION: create new method lowercase to write message with LABEL. the name of method is the LABEL in lowercase.(see example)
labelstring
- new labelcolor
- one of foreground or background. Default: cyan
- DESCRIPTION: create new method lowercase to write message with LABEL. the name of method is the LABEL in lowercase.(see example)
- message(message:string,color:string):string
- DESCRIPTION: return colored string
message
- message to message to color. Default: nullcolor
- one of foreground or background. Default: cyan
- DESCRIPTION: return colored string
- info(message:string,stack...): void
- DESCRIPTION: write in cmd a colored message with prefix label "INFO" blue
message
- message to message to color. Default: nullstack
- message to append with label INFO STACK ...
- DESCRIPTION: write in cmd a colored message with prefix label "INFO" blue
- event(message:string,stack...): void
- DESCRIPTION: write in cmd a colored message with prefix label "EVENT" blue
message
- message to message to color. Default: nullstack
- message to append with label EVENT STACK ...
- DESCRIPTION: write in cmd a colored message with prefix label "EVENT" blue
- debug(message:string,stack...): void
- DESCRIPTION: write in cmd a colored message with prefix label "DEBUG" cyan
message
- message to message to color. Default: nullstack
- message to append with label DEBUG STACK ...
- DESCRIPTION: write in cmd a colored message with prefix label "DEBUG" cyan
command(message:string): void
- DESCRIPTION: write in cmd a colored message with prefix label "COMMAND" yellow
message
- message to message to color. Default: nullstack
- message to append with label COMMAND STACK ...
- DESCRIPTION: write in cmd a colored message with prefix label "COMMAND" yellow
error(message:string): void
- DESCRIPTION: write in cmd a colored message with prefix label "ERROR" red. Error message have line before and after the message.
message
- message to message to color. Default: nullstack
- message to append with label ERROR STACK ...
- DESCRIPTION: write in cmd a colored message with prefix label "ERROR" red. Error message have line before and after the message.
printMessage(message:string,color:string):void
- DESCRIPTION: print in cmd the colored message
message
- message to message to color. Default: nullcolor
- one of foreground or background. Default: cyan
- DESCRIPTION: print in cmd the colored message
Extend before 1.1.4
class Message extends DebugMessage{
constructor(){super();}
error(m,...p){
super.error(m,...p);
process.exit();//this lock node process
}
warning(message){
this.printMessage(message,"bgyellow");
}
event(message){
let label = this._msglabel_("EVENT", "magenta");
this.printMessage(`${label} ${message}`);
}
}
Extend after >=1.1.4
mymessage= new DebugMessage();
mymessage.addLabel("labelCustom","bgyellow");
mymessage.labelcustom("a new custom label");
CHANGE LOG
- 1.1.4 added the dynamic addition to create label
- new label message "info" e "event"
- 1.1.3 fix on documentation