Last active
December 19, 2020 19:05
-
-
Save TheSainEyereg/ee65d8e324325bab41f627853a1d8236 to your computer and use it in GitHub Desktop.
Javascript debug system
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //----------------------------------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