UNPKG

1.76 kBJavaScriptView Raw
1!function(e,t){"function"==typeof define&&define.amd?define(t):"object"==typeof module&&module.exports?module.exports=t():e.prefix=t(e)}(this,function(e){"use strict";var t,r,o={template:"[%t] %l:",levelFormatter:function(e){return e.toUpperCase()},nameFormatter:function(e){return e||"root"},timestampFormatter:function(e){return e.toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/,"$1")},format:void 0},n={},a={reg:function(e){if(!e||!e.getLogger)throw new TypeError("Argument is not a root logger");t=e},apply:function(e,r){if(!e||!e.setLevel)throw new TypeError("Argument is not a logger");var a=e.methodFactory,l=e.name||"",i=n[l]||n[""]||o;return n[l]||(e.methodFactory=function(e,t,r){var o=a(e,t,r),i=n[r]||n[""],f=-1!==i.template.indexOf("%t"),p=-1!==i.template.indexOf("%l"),m=-1!==i.template.indexOf("%n");return function(){for(var t="",a=arguments.length,u=Array(a),c=0;c<a;c++)u[c]=arguments[c];if(l||!n[r]){var g=i.timestampFormatter(new Date),s=i.levelFormatter(e),d=i.nameFormatter(r);i.format?t+=i.format(s,d,g):(t+=i.template,f&&(t=t.replace(/%t/,g)),p&&(t=t.replace(/%l/,s)),m&&(t=t.replace(/%n/,d))),u.length&&"string"==typeof u[0]?u[0]=t+" "+u[0]:u.unshift(t)}o.apply(void 0,u)}}),(r=r||{}).template&&(r.format=void 0),n[l]=function(e){for(var t,r=1,o=arguments.length;r<o;r++)for(t in arguments[r])Object.prototype.hasOwnProperty.call(arguments[r],t)&&(e[t]=arguments[r][t]);return e}({},i,r),e.setLevel(e.getLevel()),t||e.warn("It is necessary to call the function reg() of loglevel-plugin-prefix before calling apply. From the next release, it will throw an error. See more: https://github.com/kutuluk/loglevel-plugin-prefix/blob/master/README.md"),e}};return e&&(r=e.prefix,a.noConflict=function(){return e.prefix===a&&(e.prefix=r),a}),a});
\No newline at end of file