Skip to content

Instantly share code, notes, and snippets.

@lynxerzhang
Last active June 12, 2017 09:12
Show Gist options
  • Select an option

  • Save lynxerzhang/7b0f9108cd14c333b82390c179f804a9 to your computer and use it in GitHub Desktop.

Select an option

Save lynxerzhang/7b0f9108cd14c333b82390c179f804a9 to your computer and use it in GitHub Desktop.

Revisions

  1. lynxerzhang revised this gist Jun 12, 2017. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions consoleUtil.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    //@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 ++){
  2. lynxerzhang created this gist Jun 12, 2017.
    23 changes: 23 additions & 0 deletions consoleUtil.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    !(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");