UNPKG

1.34 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={template:"[%t] %l:",timestampFormatter:function(e){return e.toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/,"$1")},levelFormatter:function(e){return e.toUpperCase()},nameFormatter:function(e){return e||"root"}},n={},o={apply:function(e,t){if(!e||!e.setLevel)throw new TypeError("Argument is not a logger");var o=!!e.getLogger,a=e.methodFactory,i=e.name||"",l=n[i]||n[""]||r;return n[i]||(e.methodFactory=function(e,t,r){var i=a(e,t,r),l=n[r||""],f=-1!==l.template.indexOf("%t"),p=-1!==l.template.indexOf("%l"),m=-1!==l.template.indexOf("%n");return function(){for(var t=l.template,a=arguments.length,u=Array(a),c=0;c<a;c++)u[c]=arguments[c];o&&n[r]||(f&&(t=t.replace(/%t/,l.timestampFormatter(new Date))),p&&(t=t.replace(/%l/,l.levelFormatter(e))),m&&(t=t.replace(/%n/,l.nameFormatter(r))),u.length&&"string"==typeof u[0]?u[0]=t+" "+u[0]:u.unshift(t)),i.apply(void 0,u)}}),n[i]=function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(t in arguments[r])Object.prototype.hasOwnProperty.call(arguments[r],t)&&(e[t]=arguments[r][t]);return e}({},l,t),e.setLevel(e.getLevel()),e}};return e&&(t=e.prefix,o.noConflict=function(){return e.prefix===o&&(e.prefix=t),o}),o});
\No newline at end of file