Skip to content

Instantly share code, notes, and snippets.

@dmh2
Last active February 6, 2017 05:44
Show Gist options
  • Save dmh2/d8d215798a8596b9c51703ea4f9864b2 to your computer and use it in GitHub Desktop.
Save dmh2/d8d215798a8596b9c51703ea4f9864b2 to your computer and use it in GitHub Desktop.
x-browser utility for logging styled messages to the browser JS console
class ConsoleLogUtility {
constructor() {
}
/**
* Log a message to the console and an optional bg color for compliant browser dev consoles (e.g. Chrome).
* TODO: pass a styles object for further layout specialization.
**/
consoleLog (message, bgColor='#ded') {
if(typeof(console) !== "undefined" && console.log !== undefined) {
try {
console.log('%c [' + new Date().getTime() + '] ' + message, 'background: ' + bgColor + '; color: #201; padding: 2px');
}
catch (e) {
var log = Function.prototype.bind.call(console.log, console);
log.apply(console, message);
}
}
}
}
module.exports = ConsoleLogUtility ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment