36 lines
1.1 KiB
Haxe
36 lines
1.1 KiB
Haxe
import Sys.print;
|
|
import Sys.println;
|
|
class JanBug {
|
|
//pbug is a debug function, lets easily turn on and off debugging messages
|
|
public static function pbug(text:Dynamic,?level:String="debug",?newline_after:Bool=true,?verbosity:Int=4) {
|
|
if(verbosity==0) return;
|
|
var code="";
|
|
switch level.toLowerCase(){
|
|
case "debug": if(verbosity>=4) code="\x1b[0;32;40mDEBUG> \x1b[0m";
|
|
case"info": if(verbosity>=3) code="\x1b[0;94;40mINFO > \x1b[0m";
|
|
case"warn": if(verbosity>=2) code="\x1b[0;93;40mWARN > \x1b[0m";
|
|
case "error": if(verbosity>=1) code="\x1b[0;91;40mERROR> \x1b[0m";
|
|
case _: println("Unknown Debug level!");
|
|
};
|
|
var text='$code${Std.string(text)}\x1b[0m';
|
|
if(newline_after&&(code!="")){return println(text);}
|
|
else if(code!=""){return print(text);}
|
|
else return;
|
|
};
|
|
static function main(){
|
|
|
|
//convenience variables to avoid quotes
|
|
final error="error";
|
|
final warn ="warn";
|
|
final info ="info";
|
|
final debug="debug";
|
|
|
|
pbug("default");
|
|
pbug("debug",debug);
|
|
pbug("info",info);
|
|
pbug("warn",warn);
|
|
pbug("error",error);
|
|
println("");
|
|
};
|
|
}
|