Last active
January 12, 2020 21:28
-
-
Save sbrl/613a18631561a1d63e022ae2ec324f05 to your computer and use it in GitHub Desktop.
Revisions
-
sbrl revised this gist
Jan 12, 2020 . 1 changed file with 7 additions and 5 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -22,27 +22,27 @@ class Log { debug(...message) { if(this.level > LOG_LEVELS.DEBUG) return; this.__do_log("debug", ...message); } info(...message) { if(this.level > LOG_LEVELS.INFO) return; this.__do_log("info", ...message); } log(...message) { if(this.level > LOG_LEVELS.LOG) return; this.__do_log("log", ...message); } warn(...message) { if(this.level > LOG_LEVELS.WARN) return; this.__do_log("warn", ...message); } error(...message) { if(this.level > LOG_LEVELS.ERROR) return; this.__do_log("error", ...message); } @@ -67,5 +67,7 @@ class Log { } } // You won't normally need these export { LOG_LEVELS }; export default new Log(); -
sbrl created this gist
Dec 22, 2019 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,71 @@ "use strict"; import a from './Ansi.mjs'; const LOG_LEVELS = { DEBUG: 0, INFO: 1, LOG: 2, WARN: 4, ERROR: 8, NONE: 2048 }; class Log { constructor() { this.start = new Date(); this.level = LOG_LEVELS.DEBUG; } debug(...message) { if(this.level > LOG_LEVELS.DEBUG) continue; this.__do_log("debug", ...message); } info(...message) { if(this.level > LOG_LEVELS.INFO) continue; this.__do_log("info", ...message); } log(...message) { if(this.level > LOG_LEVELS.LOG) continue; this.__do_log("log", ...message); } warn(...message) { if(this.level > LOG_LEVELS.WARN) continue; this.__do_log("warn", ...message); } error(...message) { if(this.level > LOG_LEVELS.ERROR) continue; this.__do_log("error", ...message); } __do_log(level, ...message) { message.unshift(`${a.locol}[ ${((new Date() - this.start) / 1000).toFixed(3)}]${a.reset}`); let part = `[ ${level} ]`; switch(level) { case "debug": part = a.locol + part; break; case "warn": part = a.fyellow + part; break; case "error": part = a.fred + part; break; } message.unshift(part) console.error(...message); } } export { LOG_LEVELS }; export default new Log();