Created
March 26, 2021 07:37
-
-
Save AlexMelw/1d24575807e87b0e2531e69c989a54fd to your computer and use it in GitHub Desktop.
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
//taken from http://stackoverflow.com/questions/9521921/why-does-console-log-apply-throw-an-illegal-invocation-error | |
var module = { | |
exports: {} | |
} | |
function logr() { | |
var i = -1, | |
l = arguments.length, | |
args = [], | |
fn = 'console.' + this + '(args)'; | |
while (++i < l) { | |
args.push('args[' + i + ']'); | |
} | |
fn = new Function('args', fn.replace(/args/, args.join(','))); | |
fn(arguments); | |
}; | |
var clogger = module.exports; | |
clogger.log = function (text, style) { | |
if (window.console) { | |
try { | |
var args = []; | |
if (style) { | |
args.push(style); | |
text = '%c' + text; | |
} | |
args.unshift(text); | |
console.log.apply(console, args); | |
} catch (e) { | |
logr.apply('log', arguments); | |
} | |
} | |
} | |
clogger.logGreen = function(text) { | |
this.log(text, 'background: #222222; color: #bada55'); | |
} | |
clogger.logBlue = function(text) { | |
this.log(text, 'background: #e9ff00; color: #2a1aFF'); | |
} | |
clogger.logOrange = function(text) { | |
this.log(text, 'background: #ff9f00; color: #000000'); | |
} | |
clogger.logYellow = function(text) { | |
this.log(text, 'background: #B34EE9; color: #D0FF00'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment