Created
October 23, 2012 20:57
-
-
Save chrisirhc/3941507 to your computer and use it in GitHub Desktop.
TE logging function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*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