Jump To …

log.js

(function (global) {

var log = function (id) {
  var logDiv,
    that = {},
    mode;

  if (arguments.length === 0) {
    mode = 'console';
  } else {
    mode = 'div';
  }

  function divInfo (m) {
    logDiv.innerHTML = m + '\n' + logDiv.innerHTML;
  }

  function consoleInfo (m) {
    console.log(m);
  }

  function setLogLevel (l) {
    if (l == 'debug') {
      that.debug = that.info;
    } else {
      that.debug = function () {};
    }
  }
 
  function init () {
    if (mode == 'div') {
      logDiv = document.createElement('div');
      if (id) { logDiv.id = id; }
      that.info = divInfo;
    } else if (mode == 'console') {
      that.info = consoleInfo;
    }

    return logDiv;
  }

  that.setLogLevel = setLogLevel;
  that.init = init;
  return that;
};

if (typeof module != 'undefined' && module.exports) {
  module.exports = log;
} else {
  global.trurl = global.trurl || {};
  global.trurl.log = log;
}

}(this));