UNPKG

3.34 kBJavaScriptView Raw
1/*! loglevel - v1.9.0 - https://github.com/pimterry/loglevel - (c) 2024 Tim Perry - licensed MIT */
2
3!function(e,o){"use strict";"function"==typeof define&&define.amd?define(o):"object"==typeof module&&module.exports?module.exports=o():e.log=o()}(this,function(){"use strict";var l=function(){},s="undefined",i=typeof window!==s&&typeof window.navigator!==s&&/Trident\/|MSIE /.test(window.navigator.userAgent),f=["trace","debug","info","warn","error"],p={},d=null;function r(o,e){var t=o[e];if("function"==typeof t.bind)return t.bind(o);try{return Function.prototype.bind.call(t,o)}catch(e){return function(){return Function.prototype.apply.apply(t,[o,arguments])}}}function c(){console.log&&(console.log.apply?console.log.apply(console,arguments):Function.prototype.apply.apply(console.log,[console,arguments])),console.trace&&console.trace()}function v(){for(var e=this.getLevel(),o=0;o<f.length;o++){var t=f[o];this[t]=o<e?l:this.methodFactory(t,e,this.name)}if(this.log=this.debug,typeof console===s&&e<this.levels.SILENT)return"No console available for logging"}function y(e,o,t){return"debug"===(n=e)&&(n="log"),typeof console!==s&&("trace"===n&&i?c:void 0!==console[n]?r(console,n):void 0!==console.log?r(console,"log"):l)||function(e){return function(){typeof console!==s&&(v.call(this),this[e].apply(this,arguments))}}.apply(this,arguments);var n}function t(e,o){var t,n,l,i=this,r="loglevel";function c(){var e;if(typeof window!==s&&r){try{e=window.localStorage[r]}catch(e){}if(typeof e===s)try{var o=window.document.cookie,t=encodeURIComponent(r),n=o.indexOf(t+"=");-1!==n&&(e=/^([^;]+)/.exec(o.slice(n+t.length+1))[1])}catch(e){}return void 0===i.levels[e]&&(e=void 0),e}}function a(e){var o=e;if("string"==typeof o&&void 0!==i.levels[o.toUpperCase()]&&(o=i.levels[o.toUpperCase()]),"number"==typeof o&&0<=o&&o<=i.levels.SILENT)return o;throw new TypeError("log.setLevel() called with invalid level: "+e)}"string"==typeof e?r+=":"+e:"symbol"==typeof e&&(r=void 0),i.name=e,i.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},i.methodFactory=o||y,i.getLevel=function(){return null!=l?l:null!=n?n:t},i.setLevel=function(e,o){return l=a(e),!1!==o&&function(e){var o=(f[e]||"silent").toUpperCase();if(typeof window!==s&&r){try{return window.localStorage[r]=o}catch(e){}try{window.document.cookie=encodeURIComponent(r)+"="+o+";"}catch(e){}}}(l),v.call(this)},i.setDefaultLevel=function(e){n=a(e),c()||i.setLevel(e,!1)},i.resetLevel=function(){l=null,function(){if(typeof window!==s&&r){try{window.localStorage.removeItem(r)}catch(e){}try{window.document.cookie=encodeURIComponent(r)+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC"}catch(e){}}}(),v.call(this)},i.enableAll=function(e){i.setLevel(i.levels.TRACE,e)},i.disableAll=function(e){i.setLevel(i.levels.SILENT,e)},i.rebuild=function(){if(d!==i&&(t=a(d.getLevel())),v.call(this),d===i)for(var e in p)p[e].rebuild()},t=a(d?d.getLevel():"WARN");var u=c();null!=u&&(l=a(u)),v.call(this)}(d=new t).getLogger=function(e){if("symbol"!=typeof e&&"string"!=typeof e||""===e)throw new TypeError("You must supply a name when creating a logger.");var o=p[e];return o||(o=p[e]=new t(e,d.methodFactory)),o};var e=typeof window!==s?window.log:void 0;return d.noConflict=function(){return typeof window!==s&&window.log===d&&(window.log=e),d},d.getLoggers=function(){return p},d.default=d});
\No newline at end of file