Skip to content

Instantly share code, notes, and snippets.

@spmbt
Last active December 31, 2015 11:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spmbt/7982217 to your computer and use it in GitHub Desktop.
Save spmbt/7982217 to your computer and use it in GitHub Desktop.
console,warn, .info, console.log, .error with max logLevel for output and four String.prototype functions: wcw, wci, wcl, wce.<br> Examples:<br> wcl(12,'XXX') //i.e. console.log(12,'XXX');<br> 'Error message'.wce(er) //i.e. console.error("'=E='",'Error message', er);<br>
(function(w, logLevel, wcA){ var lvl =0
,$x = function(el, h){if(h) for(var i in h) el[i] = h[i]; return el};
for(var i in wcA) //консоль[i] как метод строки или функция
w[i] = (function(lvl, wcAI, i){
return function(a){ a = a!==undefined|| arguments.length ? a :'';
if(w.console && logLevel <= lvl)
Function.prototype.apply.call(w.console[i], w.console, this instanceof String
//w.console[i].apply(console, this instanceof String //--for without IE
? [wcAI + this +"'"].concat([].slice.call(arguments))
: arguments);
else
w.console[i] = function(){};
} })(lvl++, wcA[i], {wcw:'warn', wci:'info', wcl:'log', wce:'error'}[i]);
w.wcc = w.console.clear;
$x(String.prototype, {wcw: w.wcw, wci: w.wci, wcl: w.wcl, wce: w.wce, wcc: w.wcc });
})(window, /*logLevel*/ 0, {wcw:"'-w-", wci:'--', wcl:"'==", wce:"'=E="});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment