Skip to content

Instantly share code, notes, and snippets.

@chrisirhc
Created October 23, 2012 20:57
Show Gist options
  • Save chrisirhc/3941507 to your computer and use it in GitHub Desktop.
Save chrisirhc/3941507 to your computer and use it in GitHub Desktop.
TE logging function
/*global console:true */
var te = te || {};
(function () {
var _levels = [ 'log', 'info', 'warn', 'error' ],
_noop = function () {},
_passthru = function (lvl) {
return function () { console[lvl].apply(console, arguments); };
},
_level = 0;
te.logging = {};
te.logging.getLevel = function () {
return _levels[_level];
};
te.logging.setLevel = function (newLevelName) {
var newLevel = _levels.indexOf(newLevelName),
i, levelName;
if (newLevel !== -1) {
_level = newLevel;
for (i = 0; i < _levels.length; ++i) {
levelName = _levels[i];
te.logging[levelName] = i < _level ? _noop : _passthru(levelName);
}
}
};
te.logging.setLevel('log');
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment