Last active
February 6, 2017 05:44
-
-
Save dmh2/d8d215798a8596b9c51703ea4f9864b2 to your computer and use it in GitHub Desktop.
x-browser utility for logging styled messages to the browser JS console
This file contains hidden or 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
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