Skip to content

Instantly share code, notes, and snippets.

@bang9
Last active May 24, 2022 05:20
Show Gist options
  • Save bang9/616844b7b855963d3800fed6c49cf810 to your computer and use it in GitHub Desktop.
Save bang9/616844b7b855963d3800fed6c49cf810 to your computer and use it in GitHub Desktop.
Chrome Pretty Logger
/**
* 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