Skip to content

Instantly share code, notes, and snippets.

@therealbenpai
Last active October 24, 2023 14:01
Show Gist options
  • Save therealbenpai/1b8f450de2a2197ec7a259509364dc2e to your computer and use it in GitHub Desktop.
Save therealbenpai/1b8f450de2a2197ec7a259509364dc2e to your computer and use it in GitHub Desktop.
class cLogs {
constructor() {
this.cmethods = new Map()
}
static TagCSS = (t, b) => `color:${t};border:1px solid ${t};border-radius:12px;font-size:11px;font-family:arial;background-color:rgba(${b.join(', ')},0.2);padding: 0px 3px`
static error = (msg) => console.error(`%cERROR%c ${msg ?? ""}`, this.TagCSS('red', [220, 0, 0]), '')
static warn = (msg) => console.warn(`%cWARNING%c ${msg ?? ""}`, this.TagCSS('darkorange', [240, 130, 0]), '')
static success = (msg) => console.log(`%cLOG%c ${msg ?? ""}`, this.TagCSS('green', [0, 220, 0]), '')
static customTag = (tagType = 'log', tagText= 'Filler Text', tagData = {}) => (d) => console[tagType](`%c${tagText.toUpperCase()}%c ${d}`,Object.entries(tagData).map(([k,v]) => `${k}: ${v}`).join(';'),'')
error = (msg) => cLogs.error(msg)
warn = (msg) => cLogs.warn(msg)
success = (msg) => cLogs.success(msg)
makeTag(tagType = 'log', tagText= 'Filler Text', tagData = {}, name) {
console.log([`Your method (${name}):`, cLogs.customTag(tagType, tagText, tagData).toString()].join('\n'), 'font-weight:bolder;font-family:arial;')
this.cmethods.set(name, cLogs.customTag(tagType, tagText, tagData))
}
run(name, data) {
try {
this.cmethods.get(name).call(data)
} catch (err) {
return console.error((err instanceof TypeError) ? "Invalid Index" : err)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment