//@see https://www.paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/ //inspired from paulirish's console.log function !(function(win, funNameAry, titleAry, max){ max = max || 100; for(var i = 0, funName = ""; i < funNameAry.length, funName = funNameAry[i]; i ++){ win[funName] = (function(i, n){ return function(){ this[n].history = this[n].history || []; this[n].logMax = this[n].logMax || max; this[n].history.push(arguments); if(this[n].history.length > this[n].logMax){ this[n].history = this[n].history.slice(-this[n].logMax); } if(win.console && typeof win.console[n] === "function"){ this[n].logbind = this[n].logbind || this.console[n].bind(this.console, "[" + titleAry[i] + "]"); this[n].logbind.apply(null, Array.prototype.slice.call(arguments)); } } })(i, funName); } }(window, ["log", "warn"], ["trace", "warning"])); //usage: log("trace to console"); warn("warning for something");