Skip to content

Instantly share code, notes, and snippets.

@TheSainEyereg
Last active December 19, 2020 19:05
Show Gist options
  • Select an option

  • Save TheSainEyereg/ee65d8e324325bab41f627853a1d8236 to your computer and use it in GitHub Desktop.

Select an option

Save TheSainEyereg/ee65d8e324325bab41f627853a1d8236 to your computer and use it in GitHub Desktop.
Javascript debug system
//----------------------------------Sett----------------------------------\\
const info = {
build: "Beta191220",
version: 1
}
const debug_default = "0"; //Not true or false because localStorage cannot store boolean values
const debug_time = true;
//----------------------------------Core----------------------------------\\
let debug = {
enabled: null,
initializate() {
this.enabled = localStorage.getItem("debug");
if ((this.enabled != "0") && (this.enabled != "1")) {
this.set(debug_default);
} else {
this.set(this.enabled);
}
},
set(arg) {
this.enabled = arg;
localStorage.setItem("debug", this.enabled);
debug.log("Set debug to " + arg, "#00c800");
},
log(text, color, background) {
if (this.enabled == "1") {
if (!debug_time) {
console.log("%c "+text+" ", "color: "+color+"; background: "+background);
} else {
let date = new Date;
console.log("["+date.getMinutes()+":"+date.getSeconds()+":"+date.getMilliseconds()+"]:"+"%c "+text+" ", "color: "+color+"; background: "+background);
}
}
}
};
//----------------------------------Main----------------------------------\\
debug.initializate();
debug.log("Build "+info.build+"v"+info.version, "#fff","#000");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment