Last active
January 3, 2016 21:39
-
-
Save florianboudot/8522938 to your computer and use it in GitHub Desktop.
console log with custom colors
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
var CONSOLE_CSS = 'background:#a4aa0a; color:white; padding:0 4px'; // default | |
function CustomConsole (prefix, console_css) { | |
// choose passed arg or default constant | |
console_css = console_css || CONSOLE_CSS; | |
function processArgs () { | |
var args = Array.prototype.slice.call(arguments); // converts Arguments to Array | |
args.shift(); // remove console method | |
args.unshift('%c' + prefix, console_css); // adds custom css and prefix at the beginning | |
return args; | |
} | |
function handler (type) { | |
return console[type].apply(console, processArgs.apply(this, arguments)); | |
} | |
// export public methods: .info(), .warn(), etc | |
['log', 'info', 'warn'].forEach(function(type) { | |
this[type] = handler.bind(handler, type); | |
}, this); | |
} | |
var console_css = 'background:#baff00; color:black; padding:0 4px'; | |
var _console = new CustomConsole('gameManager', console_css); | |
var truc = 'hello you'; | |
var machin = 'hello machin'; | |
_console.warn('Neo', truc, machin); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment