mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
3 lines
4.5 KiB
JavaScript
3 lines
4.5 KiB
JavaScript
var root,definition;root=window,definition=function(){var noop=function(){},isIE="undefined"!=typeof window&&void 0!==window.navigator&&/Trident\/|MSIE /.test(window.navigator.userAgent),logMethods=["trace","debug","info","warn","error"];function bindMethod(obj,methodName){var method=obj[methodName];if("function"==typeof method.bind)return method.bind(obj);try{return Function.prototype.bind.call(method,obj)}catch(e){return function(){return Function.prototype.apply.apply(method,[obj,arguments])}}}function traceForIE(){console.log&&(console.log.apply?console.log.apply(console,arguments):Function.prototype.apply.apply(console.log,[console,arguments])),console.trace&&console.trace()}function realMethod(methodName){return"debug"===methodName&&(methodName="log"),"undefined"!=typeof console&&("trace"===methodName&&isIE?traceForIE:void 0!==console[methodName]?bindMethod(console,methodName):void 0!==console.log?bindMethod(console,"log"):noop)}function replaceLoggingMethods(level,loggerName){for(var i=0;i<logMethods.length;i++){var methodName=logMethods[i];this[methodName]=i<level?noop:this.methodFactory(methodName,level,loggerName)}this.log=this.debug}function enableLoggingWhenConsoleArrives(methodName,level,loggerName){return function(){"undefined"!=typeof console&&(replaceLoggingMethods.call(this,level,loggerName),this[methodName].apply(this,arguments))}}function defaultMethodFactory(methodName,level,loggerName){return realMethod(methodName)||enableLoggingWhenConsoleArrives.apply(this,arguments)}function Logger(name,defaultLevel,factory){var currentLevel,self=this;defaultLevel=null==defaultLevel?"WARN":defaultLevel;var storageKey="loglevel";function getPersistedLevel(){var storedLevel;if("undefined"!=typeof window&&storageKey){try{storedLevel=window.localStorage[storageKey]}catch(ignore){}if(void 0===storedLevel)try{var cookie=window.document.cookie,location=cookie.indexOf(encodeURIComponent(storageKey)+"=");-1!==location&&(storedLevel=/^([^;]+)/.exec(cookie.slice(location))[1])}catch(ignore){}return void 0===self.levels[storedLevel]&&(storedLevel=void 0),storedLevel}}"string"==typeof name?storageKey+=":"+name:"symbol"==typeof name&&(storageKey=void 0),self.name=name,self.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},self.methodFactory=factory||defaultMethodFactory,self.getLevel=function(){return currentLevel},self.setLevel=function(level,persist){if("string"==typeof level&&void 0!==self.levels[level.toUpperCase()]&&(level=self.levels[level.toUpperCase()]),!("number"==typeof level&&level>=0&&level<=self.levels.SILENT))throw"log.setLevel() called with invalid level: "+level;if(currentLevel=level,!1!==persist&&function(levelNum){var levelName=(logMethods[levelNum]||"silent").toUpperCase();if("undefined"!=typeof window&&storageKey){try{return void(window.localStorage[storageKey]=levelName)}catch(ignore){}try{window.document.cookie=encodeURIComponent(storageKey)+"="+levelName+";"}catch(ignore){}}}(level),replaceLoggingMethods.call(self,level,name),"undefined"==typeof console&&level<self.levels.SILENT)return"No console available for logging"},self.setDefaultLevel=function(level){defaultLevel=level,getPersistedLevel()||self.setLevel(level,!1)},self.resetLevel=function(){self.setLevel(defaultLevel,!1),function(){if("undefined"!=typeof window&&storageKey){try{return void window.localStorage.removeItem(storageKey)}catch(ignore){}try{window.document.cookie=encodeURIComponent(storageKey)+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC"}catch(ignore){}}}()},self.enableAll=function(persist){self.setLevel(self.levels.TRACE,persist)},self.disableAll=function(persist){self.setLevel(self.levels.SILENT,persist)};var initialLevel=getPersistedLevel();null==initialLevel&&(initialLevel=defaultLevel),self.setLevel(initialLevel,!1)}var defaultLogger=new Logger,_loggersByName={};defaultLogger.getLogger=function(name){if("symbol"!=typeof name&&"string"!=typeof name||""===name)throw new TypeError("You must supply a name when creating a logger.");var logger=_loggersByName[name];return logger||(logger=_loggersByName[name]=new Logger(name,defaultLogger.getLevel(),defaultLogger.methodFactory)),logger};var _log="undefined"!=typeof window?window.log:void 0;return defaultLogger.noConflict=function(){return"undefined"!=typeof window&&window.log===defaultLogger&&(window.log=_log),defaultLogger},defaultLogger.getLoggers=function(){return _loggersByName},defaultLogger.default=defaultLogger,defaultLogger},"function"==typeof define&&define.amd?define("core/loglevel",definition):"object"==typeof module&&module.exports?module.exports=definition():root.log=definition();
|
|
|
|
//# sourceMappingURL=loglevel.min.js.map
|