Last active
May 24, 2022 05:20
-
-
Save bang9/616844b7b855963d3800fed6c49cf810 to your computer and use it in GitHub Desktop.
Chrome Pretty Logger
This file contains 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
/** | |
* Usage | |
* const log = Logger.log("LogTitle"); | |
* const warn = Logger.warn("WarnTitle"); | |
* | |
* log("some test log") | |
*/ | |
const LogBase = function(prefix, backgroundColor = '#0085ff', textColor = '#ffffff') { | |
this.prefix = prefix; | |
this.style = `background: ${backgroundColor}; color: ${textColor}; padding:5px 8px 5px 8px; margin-right:4px; border-radius:10px;`; | |
return (...params) => console.log(`%c${this.prefix}`, this.style, ...params); | |
}; | |
const Logger = { | |
log : (prefix) => new LogBase(prefix), | |
info : (prefix) => new LogBase(prefix, '#2da25b'), | |
warn : (prefix) => new LogBase(prefix, '#ffae42'), | |
err : (prefix) => new LogBase(prefix, '#f04336'), | |
}; | |
export default Logger; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment