-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVibrantLogger.min.js
2 lines (2 loc) · 2.24 KB
/
VibrantLogger.min.js
1
2
/** * VibrantLogger.js * A simple console logger with visual style for your projects. * @version 1.1.0 * @author JMcrafter26 <jm26.net> * @see {@link https://jm26.net} * @see {@link https://github.com/JMcrafter26/vibrant-logger.js} * @license MIT */
class Logger{constructor(t){"object"!=typeof t&&(t={}),this.name=t.name||"",this.theme=t.theme||"auto";var o=t.customColors||{};this.style=t.style||"auto",this.colorsDark={INFO:"#82AAFF",WARN:"#FFCB6B",ERROR:"#FF5370",SUCCESS:"#C3E88D",DEBUG:"#d382ff",UNKNOWN:"#abb2bf",background:"#434C5E"},this.colorsLight={INFO:"#407dff",WARN:"#ffb62e",ERROR:"#FF5370",SUCCESS:"#a0db48",DEBUG:"#bc40ff",UNKNOWN:"#6e7685",background:"#F5F5F5"},"object"!=typeof o&&(o={}),"dark"!==this.theme&&"light"!==this.theme&&"auto"!==this.theme&&0===Object.keys(o).length?this.colors=this.colorsDark:("auto"===this.theme&&(window.matchMedia&&window.matchMedia("(prefers-color-scheme: light)").matches?this.theme="light":this.theme="dark"),"dark"===this.theme&&(this.colors=this.colorsDark),"light"===this.theme&&(this.colors=this.colorsLight),0!==Object.keys(o).length&&(this.colors=o))}log(t="No message provided",o="INFO"){const s=o;this.colors[o]||(o="UNKNOWN"),"time"===this.name&&(this.name=(new Date).toLocaleTimeString());var i=(new Error).stack.split("\n")[2].split("/").pop().split(":")[0];const e=7*(t.length+o.length+this.name.length+6)>window.outerWidth-window.innerWidth-i.length-180;var h,r,c;h="maxi"!==this.style||e?""===this.name?"%c "+s+" %c "+t+" ":"%c "+this.name+" "+s+" %c "+t+" ":""===this.name?"%c "+s+"\n%c "+t+" ":"%c "+this.name+" "+s+"\n%c "+t+" ",e||"auto"!==this.style?(e||"maxi"===this.style)&&(r=`background: ${this.colors[o]}; color: ${this.colors.background}; padding: 1px; border-radius: 3px 3px 0 0;`,c=`background: ${this.colors.background}; color: ${this.colors[o]}; padding: 1px; border-radius: 0 3px 3px 3px;`):(r=`background: ${this.colors[o]}; color: ${this.colors.background}; padding: 1px; border-radius: 3px 0 0 3px;`,c=`background: ${this.colors.background}; color: ${this.colors[o]}; padding: 1px; border-radius: 0 3px 3px 0;`),console.log(h,r,c)}info(t){this.log(t,"INFO")}warn(t){this.log(t,"WARN")}error(t){this.log(t,"ERROR")}success(t){this.log(t,"SUCCESS")}debug(t){this.log(t,"DEBUG")}unknown(t){this.log(t,"UNKNOWN")}}