@libp2p/logger 3.0.5 → 3.1.0-0f5c305af

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,3 +1,3 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PLogger = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PLogger=(()=>{var re=Object.create;var P=Object.defineProperty;var te=Object.getOwnPropertyDescriptor;var ne=Object.getOwnPropertyNames;var oe=Object.getPrototypeOf,se=Object.prototype.hasOwnProperty;var $=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports),ae=(e,r)=>{for(var t in r)P(e,t,{get:r[t],enumerable:!0})},T=(e,r,t,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let a of ne(r))!se.call(e,a)&&a!==t&&P(e,a,{get:()=>r[a],enumerable:!(o=te(r,a))||o.enumerable});return e};var ie=(e,r,t)=>(t=e!=null?re(oe(e)):{},T(r||!e||!e.__esModule?P(t,"default",{value:e,enumerable:!0}):t,e)),ce=e=>T(P({},"__esModule",{value:!0}),e);var V=$((Pe,q)=>{var M=1e3,z=M*60,O=z*60,U=O*24,fe=U*7,ue=U*365.25;q.exports=function(e,r){r=r||{};var t=typeof e;if(t==="string"&&e.length>0)return de(e);if(t==="number"&&isFinite(e))return r.long?pe(e):le(e);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))};function de(e){if(e=String(e),!(e.length>100)){var r=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(e);if(r){var t=parseFloat(r[1]),o=(r[2]||"ms").toLowerCase();switch(o){case"years":case"year":case"yrs":case"yr":case"y":return t*ue;case"weeks":case"week":case"w":return t*fe;case"days":case"day":case"d":return t*U;case"hours":case"hour":case"hrs":case"hr":case"h":return t*O;case"minutes":case"minute":case"mins":case"min":case"m":return t*z;case"seconds":case"second":case"secs":case"sec":case"s":return t*M;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return t;default:return}}}}function le(e){var r=Math.abs(e);return r>=U?Math.round(e/U)+"d":r>=O?Math.round(e/O)+"h":r>=z?Math.round(e/z)+"m":r>=M?Math.round(e/M)+"s":e+"ms"}function pe(e){var r=Math.abs(e);return r>=U?j(e,r,U,"day"):r>=O?j(e,r,O,"hour"):r>=z?j(e,r,z,"minute"):r>=M?j(e,r,M,"second"):e+" ms"}function j(e,r,t,o){var a=r>=t*1.5;return Math.round(e/t)+" "+o+(a?"s":"")}});var X=$((je,G)=>{function he(e){t.debug=t,t.default=t,t.coerce=w,t.disable=p,t.enable=a,t.enabled=m,t.humanize=V(),t.destroy=N,Object.keys(e).forEach(n=>{t[n]=e[n]}),t.names=[],t.skips=[],t.formatters={};function r(n){let s=0;for(let f=0;f<n.length;f++)s=(s<<5)-s+n.charCodeAt(f),s|=0;return t.colors[Math.abs(s)%t.colors.length]}t.selectColor=r;function t(n){let s,f=null,S,i;function c(...d){if(!c.enabled)return;let l=c,C=Number(new Date),F=C-(s||C);l.diff=F,l.prev=s,l.curr=C,s=C,d[0]=t.coerce(d[0]),typeof d[0]!="string"&&d.unshift("%O");let h=0;d[0]=d[0].replace(/%([a-zA-Z%])/g,(v,y)=>{if(v==="%%")return"%";h++;let A=t.formatters[y];if(typeof A=="function"){let k=d[h];v=A.call(l,k),d.splice(h,1),h--}return v}),t.formatArgs.call(l,d),(l.log||t.log).apply(l,d)}return c.namespace=n,c.useColors=t.useColors(),c.color=t.selectColor(n),c.extend=o,c.destroy=t.destroy,Object.defineProperty(c,"enabled",{enumerable:!0,configurable:!1,get:()=>f!==null?f:(S!==t.namespaces&&(S=t.namespaces,i=t.enabled(n)),i),set:d=>{f=d}}),typeof t.init=="function"&&t.init(c),c}function o(n,s){let f=t(this.namespace+(typeof s>"u"?":":s)+n);return f.log=this.log,f}function a(n){t.save(n),t.namespaces=n,t.names=[],t.skips=[];let s,f=(typeof n=="string"?n:"").split(/[\s,]+/),S=f.length;for(s=0;s<S;s++)f[s]&&(n=f[s].replace(/\*/g,".*?"),n[0]==="-"?t.skips.push(new RegExp("^"+n.slice(1)+"$")):t.names.push(new RegExp("^"+n+"$")))}function p(){let n=[...t.names.map(u),...t.skips.map(u).map(s=>"-"+s)].join(",");return t.enable(""),n}function m(n){if(n[n.length-1]==="*")return!0;let s,f;for(s=0,f=t.skips.length;s<f;s++)if(t.skips[s].test(n))return!1;for(s=0,f=t.names.length;s<f;s++)if(t.names[s].test(n))return!0;return!1}function u(n){return n.toString().substring(2,n.toString().length-2).replace(/\.\*\?$/,"*")}function w(n){return n instanceof Error?n.stack||n.message:n}function N(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return t.enable(t.load()),t}G.exports=he});var Z=$((x,I)=>{x.formatArgs=Ce;x.save=ge;x.load=me;x.useColors=be;x.storage=we();x.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})();x.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function be(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)?!1:typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function Ce(e){if(e[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+e[0]+(this.useColors?"%c ":" ")+"+"+I.exports.humanize(this.diff),!this.useColors)return;let r="color: "+this.color;e.splice(1,0,r,"color: inherit");let t=0,o=0;e[0].replace(/%[a-zA-Z%]/g,a=>{a!=="%%"&&(t++,a==="%c"&&(o=t))}),e.splice(o,0,r)}x.log=console.debug||console.log||(()=>{});function ge(e){try{e?x.storage.setItem("debug",e):x.storage.removeItem("debug")}catch{}}function me(){let e;try{e=x.storage.getItem("debug")}catch{}return!e&&typeof process<"u"&&"env"in process&&(e=process.env.DEBUG),e}function we(){try{return localStorage}catch{}}I.exports=X()(x);var{formatters:ye}=I.exports;ye.j=function(e){try{return JSON.stringify(e)}catch(r){return"[UnexpectedJSONParseError]: "+r.message}}});var Oe={};ae(Oe,{disable:()=>ke,enable:()=>Me,enabled:()=>ze,logger:()=>Se});var b=ie(Z(),1);function xe(e,r){if(e.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),o=0;o<t.length;o++)t[o]=255;for(var a=0;a<e.length;a++){var p=e.charAt(a),m=p.charCodeAt(0);if(t[m]!==255)throw new TypeError(p+" is ambiguous");t[m]=a}var u=e.length,w=e.charAt(0),N=Math.log(u)/Math.log(256),n=Math.log(256)/Math.log(u);function s(i){if(i instanceof Uint8Array||(ArrayBuffer.isView(i)?i=new Uint8Array(i.buffer,i.byteOffset,i.byteLength):Array.isArray(i)&&(i=Uint8Array.from(i))),!(i instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(i.length===0)return"";for(var c=0,d=0,l=0,C=i.length;l!==C&&i[l]===0;)l++,c++;for(var F=(C-l)*n+1>>>0,h=new Uint8Array(F);l!==C;){for(var E=i[l],v=0,y=F-1;(E!==0||v<d)&&y!==-1;y--,v++)E+=256*h[y]>>>0,h[y]=E%u>>>0,E=E/u>>>0;if(E!==0)throw new Error("Non-zero carry");d=v,l++}for(var A=F-d;A!==F&&h[A]===0;)A++;for(var k=w.repeat(c);A<F;++A)k+=e.charAt(h[A]);return k}function f(i){if(typeof i!="string")throw new TypeError("Expected String");if(i.length===0)return new Uint8Array;var c=0;if(i[c]!==" "){for(var d=0,l=0;i[c]===w;)d++,c++;for(var C=(i.length-c)*N+1>>>0,F=new Uint8Array(C);i[c];){var h=t[i.charCodeAt(c)];if(h===255)return;for(var E=0,v=C-1;(h!==0||E<l)&&v!==-1;v--,E++)h+=u*F[v]>>>0,F[v]=h%256>>>0,h=h/256>>>0;if(h!==0)throw new Error("Non-zero carry");l=E,c++}if(i[c]!==" "){for(var y=C-l;y!==C&&F[y]===0;)y++;for(var A=new Uint8Array(d+(C-y)),k=d;y!==C;)A[k++]=F[y++];return A}}}function S(i){var c=f(i);if(c)return c;throw new Error(`Non-${r} character`)}return{encode:s,decodeUnsafe:f,decode:S}}var Fe=xe,ve=Fe,K=ve;var $e=new Uint8Array(0);var Q=e=>{if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")};var D=class{constructor(r,t,o){this.name=r,this.prefix=t,this.baseEncode=o}encode(r){if(r instanceof Uint8Array)return`${this.prefix}${this.baseEncode(r)}`;throw Error("Unknown type, must be binary type")}},L=class{constructor(r,t,o){if(this.name=r,this.prefix=t,t.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=t.codePointAt(0),this.baseDecode=o}decode(r){if(typeof r=="string"){if(r.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(r)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(r.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(r){return _(this,r)}},R=class{constructor(r){this.decoders=r}or(r){return _(this,r)}decode(r){let t=r[0],o=this.decoders[t];if(o)return o.decode(r);throw RangeError(`Unable to decode multibase string ${JSON.stringify(r)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}},_=(e,r)=>new R({...e.decoders||{[e.prefix]:e},...r.decoders||{[r.prefix]:r}}),B=class{constructor(r,t,o,a){this.name=r,this.prefix=t,this.baseEncode=o,this.baseDecode=a,this.encoder=new D(r,t,o),this.decoder=new L(r,t,a)}encode(r){return this.encoder.encode(r)}decode(r){return this.decoder.decode(r)}},W=({name:e,prefix:r,encode:t,decode:o})=>new B(e,r,t,o),J=({prefix:e,name:r,alphabet:t})=>{let{encode:o,decode:a}=K(t,r);return W({prefix:e,name:r,encode:o,decode:p=>Q(a(p))})},Ae=(e,r,t,o)=>{let a={};for(let n=0;n<r.length;++n)a[r[n]]=n;let p=e.length;for(;e[p-1]==="=";)--p;let m=new Uint8Array(p*t/8|0),u=0,w=0,N=0;for(let n=0;n<p;++n){let s=a[e[n]];if(s===void 0)throw new SyntaxError(`Non-${o} character`);w=w<<t|s,u+=t,u>=8&&(u-=8,m[N++]=255&w>>u)}if(u>=t||255&w<<8-u)throw new SyntaxError("Unexpected end of data");return m},Ee=(e,r,t)=>{let o=r[r.length-1]==="=",a=(1<<t)-1,p="",m=0,u=0;for(let w=0;w<e.length;++w)for(u=u<<8|e[w],m+=8;m>t;)m-=t,p+=r[a&u>>m];if(m&&(p+=r[a&u<<t-m]),o)for(;p.length*t&7;)p+="=";return p},g=({name:e,prefix:r,bitsPerChar:t,alphabet:o})=>W({prefix:r,name:e,encode(a){return Ee(a,o,t)},decode(a){return Ae(a,o,t,e)}});var Y=g({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Te=g({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),qe=g({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Ve=g({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ge=g({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Xe=g({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ze=g({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Ke=g({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Qe=g({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var H=J({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ye=J({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ee=g({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),rr=g({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),tr=g({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),nr=g({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});b.default.formatters.b=e=>e==null?"undefined":H.baseEncode(e);b.default.formatters.t=e=>e==null?"undefined":Y.baseEncode(e);b.default.formatters.m=e=>e==null?"undefined":ee.baseEncode(e);b.default.formatters.p=e=>e==null?"undefined":e.toString();b.default.formatters.c=e=>e==null?"undefined":e.toString();b.default.formatters.k=e=>e==null?"undefined":e.toString();b.default.formatters.a=e=>e==null?"undefined":e.toString();function Ue(e){let r=()=>{};return r.enabled=!1,r.color="",r.diff=0,r.log=()=>{},r.namespace=e,r.destroy=()=>!0,r.extend=()=>r,r}function Se(e){let r=Ue(`${e}:trace`);return b.default.enabled(`${e}:trace`)&&b.default.names.map(t=>t.toString()).find(t=>t.includes(":trace"))!=null&&(r=(0,b.default)(`${e}:trace`)),Object.assign((0,b.default)(e),{error:(0,b.default)(`${e}:error`),trace:r})}function ke(){b.default.disable()}function Me(e){b.default.enable(e)}function ze(e){return b.default.enabled(e)}return ce(Oe);})();
2
+ "use strict";var Libp2PLogger=(()=>{var oe=Object.create;var I=Object.defineProperty;var se=Object.getOwnPropertyDescriptor;var ae=Object.getOwnPropertyNames;var ie=Object.getPrototypeOf,ce=Object.prototype.hasOwnProperty;var N=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports),fe=(e,r)=>{for(var t in r)I(e,t,{get:r[t],enumerable:!0})},q=(e,r,t,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of ae(r))!ce.call(e,s)&&s!==t&&I(e,s,{get:()=>r[s],enumerable:!(o=se(r,s))||o.enumerable});return e};var ue=(e,r,t)=>(t=e!=null?oe(ie(e)):{},q(r||!e||!e.__esModule?I(t,"default",{value:e,enumerable:!0}):t,e)),de=e=>q(I({},"__esModule",{value:!0}),e);var G=N((je,V)=>{var L=1e3,M=L*60,z=M*60,U=z*24,le=U*7,pe=U*365.25;V.exports=function(e,r){r=r||{};var t=typeof e;if(t==="string"&&e.length>0)return he(e);if(t==="number"&&isFinite(e))return r.long?Ce(e):be(e);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))};function he(e){if(e=String(e),!(e.length>100)){var r=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(e);if(r){var t=parseFloat(r[1]),o=(r[2]||"ms").toLowerCase();switch(o){case"years":case"year":case"yrs":case"yr":case"y":return t*pe;case"weeks":case"week":case"w":return t*le;case"days":case"day":case"d":return t*U;case"hours":case"hour":case"hrs":case"hr":case"h":return t*z;case"minutes":case"minute":case"mins":case"min":case"m":return t*M;case"seconds":case"second":case"secs":case"sec":case"s":return t*L;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return t;default:return}}}}function be(e){var r=Math.abs(e);return r>=U?Math.round(e/U)+"d":r>=z?Math.round(e/z)+"h":r>=M?Math.round(e/M)+"m":r>=L?Math.round(e/L)+"s":e+"ms"}function Ce(e){var r=Math.abs(e);return r>=U?P(e,r,U,"day"):r>=z?P(e,r,z,"hour"):r>=M?P(e,r,M,"minute"):r>=L?P(e,r,L,"second"):e+" ms"}function P(e,r,t,o){var s=r>=t*1.5;return Math.round(e/t)+" "+o+(s?"s":"")}});var Z=N((De,X)=>{function ge(e){t.debug=t,t.default=t,t.coerce=w,t.disable=p,t.enable=s,t.enabled=m,t.humanize=G(),t.destroy=O,Object.keys(e).forEach(n=>{t[n]=e[n]}),t.names=[],t.skips=[],t.formatters={};function r(n){let a=0;for(let f=0;f<n.length;f++)a=(a<<5)-a+n.charCodeAt(f),a|=0;return t.colors[Math.abs(a)%t.colors.length]}t.selectColor=r;function t(n){let a,f=null,S,i;function c(...d){if(!c.enabled)return;let l=c,C=Number(new Date),F=C-(a||C);l.diff=F,l.prev=a,l.curr=C,a=C,d[0]=t.coerce(d[0]),typeof d[0]!="string"&&d.unshift("%O");let h=0;d[0]=d[0].replace(/%([a-zA-Z%])/g,(v,x)=>{if(v==="%%")return"%";h++;let A=t.formatters[x];if(typeof A=="function"){let k=d[h];v=A.call(l,k),d.splice(h,1),h--}return v}),t.formatArgs.call(l,d),(l.log||t.log).apply(l,d)}return c.namespace=n,c.useColors=t.useColors(),c.color=t.selectColor(n),c.extend=o,c.destroy=t.destroy,Object.defineProperty(c,"enabled",{enumerable:!0,configurable:!1,get:()=>f!==null?f:(S!==t.namespaces&&(S=t.namespaces,i=t.enabled(n)),i),set:d=>{f=d}}),typeof t.init=="function"&&t.init(c),c}function o(n,a){let f=t(this.namespace+(typeof a>"u"?":":a)+n);return f.log=this.log,f}function s(n){t.save(n),t.namespaces=n,t.names=[],t.skips=[];let a,f=(typeof n=="string"?n:"").split(/[\s,]+/),S=f.length;for(a=0;a<S;a++)f[a]&&(n=f[a].replace(/\*/g,".*?"),n[0]==="-"?t.skips.push(new RegExp("^"+n.slice(1)+"$")):t.names.push(new RegExp("^"+n+"$")))}function p(){let n=[...t.names.map(u),...t.skips.map(u).map(a=>"-"+a)].join(",");return t.enable(""),n}function m(n){if(n[n.length-1]==="*")return!0;let a,f;for(a=0,f=t.skips.length;a<f;a++)if(t.skips[a].test(n))return!1;for(a=0,f=t.names.length;a<f;a++)if(t.names[a].test(n))return!0;return!1}function u(n){return n.toString().substring(2,n.toString().length-2).replace(/\.\*\?$/,"*")}function w(n){return n instanceof Error?n.stack||n.message:n}function O(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return t.enable(t.load()),t}X.exports=ge});var K=N((y,$)=>{y.formatArgs=we;y.save=xe;y.load=ye;y.useColors=me;y.storage=Fe();y.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})();y.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function me(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)?!1:typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function we(e){if(e[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+e[0]+(this.useColors?"%c ":" ")+"+"+$.exports.humanize(this.diff),!this.useColors)return;let r="color: "+this.color;e.splice(1,0,r,"color: inherit");let t=0,o=0;e[0].replace(/%[a-zA-Z%]/g,s=>{s!=="%%"&&(t++,s==="%c"&&(o=t))}),e.splice(o,0,r)}y.log=console.debug||console.log||(()=>{});function xe(e){try{e?y.storage.setItem("debug",e):y.storage.removeItem("debug")}catch{}}function ye(){let e;try{e=y.storage.getItem("debug")}catch{}return!e&&typeof process<"u"&&"env"in process&&(e=process.env.DEBUG),e}function Fe(){try{return localStorage}catch{}}$.exports=Z()(y);var{formatters:ve}=$.exports;ve.j=function(e){try{return JSON.stringify(e)}catch(r){return"[UnexpectedJSONParseError]: "+r.message}}});var $e={};fe($e,{defaultLogger:()=>ze,disable:()=>Oe,enable:()=>Ie,enabled:()=>Pe,logger:()=>T,peerLogger:()=>Me,prefixLogger:()=>ne});var b=ue(K(),1);function Ae(e,r){if(e.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),o=0;o<t.length;o++)t[o]=255;for(var s=0;s<e.length;s++){var p=e.charAt(s),m=p.charCodeAt(0);if(t[m]!==255)throw new TypeError(p+" is ambiguous");t[m]=s}var u=e.length,w=e.charAt(0),O=Math.log(u)/Math.log(256),n=Math.log(256)/Math.log(u);function a(i){if(i instanceof Uint8Array||(ArrayBuffer.isView(i)?i=new Uint8Array(i.buffer,i.byteOffset,i.byteLength):Array.isArray(i)&&(i=Uint8Array.from(i))),!(i instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(i.length===0)return"";for(var c=0,d=0,l=0,C=i.length;l!==C&&i[l]===0;)l++,c++;for(var F=(C-l)*n+1>>>0,h=new Uint8Array(F);l!==C;){for(var E=i[l],v=0,x=F-1;(E!==0||v<d)&&x!==-1;x--,v++)E+=256*h[x]>>>0,h[x]=E%u>>>0,E=E/u>>>0;if(E!==0)throw new Error("Non-zero carry");d=v,l++}for(var A=F-d;A!==F&&h[A]===0;)A++;for(var k=w.repeat(c);A<F;++A)k+=e.charAt(h[A]);return k}function f(i){if(typeof i!="string")throw new TypeError("Expected String");if(i.length===0)return new Uint8Array;var c=0;if(i[c]!==" "){for(var d=0,l=0;i[c]===w;)d++,c++;for(var C=(i.length-c)*O+1>>>0,F=new Uint8Array(C);i[c];){var h=t[i.charCodeAt(c)];if(h===255)return;for(var E=0,v=C-1;(h!==0||E<l)&&v!==-1;v--,E++)h+=u*F[v]>>>0,F[v]=h%256>>>0,h=h/256>>>0;if(h!==0)throw new Error("Non-zero carry");l=E,c++}if(i[c]!==" "){for(var x=C-l;x!==C&&F[x]===0;)x++;for(var A=new Uint8Array(d+(C-x)),k=d;x!==C;)A[k++]=F[x++];return A}}}function S(i){var c=f(i);if(c)return c;throw new Error(`Non-${r} character`)}return{encode:a,decodeUnsafe:f,decode:S}}var Ee=Ae,Ue=Ee,Q=Ue;var Be=new Uint8Array(0);var _=e=>{if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")};var j=class{constructor(r,t,o){this.name=r,this.prefix=t,this.baseEncode=o}encode(r){if(r instanceof Uint8Array)return`${this.prefix}${this.baseEncode(r)}`;throw Error("Unknown type, must be binary type")}},D=class{constructor(r,t,o){if(this.name=r,this.prefix=t,t.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=t.codePointAt(0),this.baseDecode=o}decode(r){if(typeof r=="string"){if(r.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(r)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(r.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(r){return W(this,r)}},R=class{constructor(r){this.decoders=r}or(r){return W(this,r)}decode(r){let t=r[0],o=this.decoders[t];if(o)return o.decode(r);throw RangeError(`Unable to decode multibase string ${JSON.stringify(r)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}},W=(e,r)=>new R({...e.decoders||{[e.prefix]:e},...r.decoders||{[r.prefix]:r}}),B=class{constructor(r,t,o,s){this.name=r,this.prefix=t,this.baseEncode=o,this.baseDecode=s,this.encoder=new j(r,t,o),this.decoder=new D(r,t,s)}encode(r){return this.encoder.encode(r)}decode(r){return this.decoder.decode(r)}},Y=({name:e,prefix:r,encode:t,decode:o})=>new B(e,r,t,o),J=({prefix:e,name:r,alphabet:t})=>{let{encode:o,decode:s}=Q(t,r);return Y({prefix:e,name:r,encode:o,decode:p=>_(s(p))})},Se=(e,r,t,o)=>{let s={};for(let n=0;n<r.length;++n)s[r[n]]=n;let p=e.length;for(;e[p-1]==="=";)--p;let m=new Uint8Array(p*t/8|0),u=0,w=0,O=0;for(let n=0;n<p;++n){let a=s[e[n]];if(a===void 0)throw new SyntaxError(`Non-${o} character`);w=w<<t|a,u+=t,u>=8&&(u-=8,m[O++]=255&w>>u)}if(u>=t||255&w<<8-u)throw new SyntaxError("Unexpected end of data");return m},ke=(e,r,t)=>{let o=r[r.length-1]==="=",s=(1<<t)-1,p="",m=0,u=0;for(let w=0;w<e.length;++w)for(u=u<<8|e[w],m+=8;m>t;)m-=t,p+=r[s&u>>m];if(m&&(p+=r[s&u<<t-m]),o)for(;p.length*t&7;)p+="=";return p},g=({name:e,prefix:r,bitsPerChar:t,alphabet:o})=>Y({prefix:r,name:e,encode(s){return ke(s,o,t)},decode(s){return Se(s,o,t,e)}});var H=g({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Xe=g({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ze=g({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Ke=g({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Qe=g({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),_e=g({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),We=g({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Ye=g({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),He=g({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ee=J({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),tr=J({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var re=g({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),sr=g({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),ar=g({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),ir=g({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});function te(e,r={}){let t=r.prefixLength??2,o=r.suffixLength??4,s=e.toString();return`${s.substring(0,t)}\u2026${s.substring(s.length,s.length-o)}`}b.default.formatters.b=e=>e==null?"undefined":ee.baseEncode(e);b.default.formatters.t=e=>e==null?"undefined":H.baseEncode(e);b.default.formatters.m=e=>e==null?"undefined":re.baseEncode(e);b.default.formatters.p=e=>e==null?"undefined":e.toString();b.default.formatters.c=e=>e==null?"undefined":e.toString();b.default.formatters.k=e=>e==null?"undefined":e.toString();b.default.formatters.a=e=>e==null?"undefined":e.toString();function Le(e){let r=()=>{};return r.enabled=!1,r.color="",r.diff=0,r.log=()=>{},r.namespace=e,r.destroy=()=>!0,r.extend=()=>r,r}function Me(e,r={}){return ne(te(e,r))}function ne(e){return{forComponent(r){return T(`${e}:${r}`)}}}function ze(){return{forComponent(e){return T(e)}}}function T(e){let r=Le(`${e}:trace`);return b.default.enabled(`${e}:trace`)&&b.default.names.map(t=>t.toString()).find(t=>t.includes(":trace"))!=null&&(r=(0,b.default)(`${e}:trace`)),Object.assign((0,b.default)(e),{error:(0,b.default)(`${e}:error`),trace:r})}function Oe(){b.default.disable()}function Ie(e){b.default.enable(e)}function Pe(e){return b.default.enabled(e)}return de($e);})();
3
3
  return Libp2PLogger}));
@@ -1,9 +1,8 @@
1
1
  /**
2
2
  * @packageDocumentation
3
3
  *
4
- * A map that reports it's size to the libp2p [Metrics](https://github.com/libp2p/js-libp2p-interfaces/tree/master/packages/libp2p-interfaces/src/metrics#readme) system.
5
- *
6
- * If metrics are disabled a regular map is used.
4
+ * A logger for libp2p based on the venerable [debug](https://www.npmjs.com/package/debug)
5
+ * module.
7
6
  *
8
7
  * @example
9
8
  *
@@ -28,12 +27,86 @@
28
27
  * with this base32: bafyfoo
29
28
  * ```
30
29
  */
30
+ import type { PeerId } from '@libp2p/interface/peer-id';
31
31
  export interface Logger {
32
32
  (formatter: any, ...args: any[]): void;
33
33
  error(formatter: any, ...args: any[]): void;
34
34
  trace(formatter: any, ...args: any[]): void;
35
35
  enabled: boolean;
36
36
  }
37
+ export interface ComponentLogger {
38
+ forComponent(name: string): Logger;
39
+ }
40
+ export interface PeerLoggerOptions {
41
+ prefixLength: number;
42
+ suffixLength: number;
43
+ }
44
+ /**
45
+ * Create a component logger that will prefix any log messages with a truncated
46
+ * peer id.
47
+ *
48
+ * @example
49
+ *
50
+ * ```TypeScript
51
+ * import { peerLogger } from '@libp2p/logger'
52
+ * import { peerIdFromString } from '@libp2p/peer-id'
53
+ *
54
+ * const peerId = peerIdFromString('12D3FooBar')
55
+ * const logger = peerLogger(peerId)
56
+ *
57
+ * const log = logger.forComponent('my-component')
58
+ * log.info('hello world')
59
+ * // logs "12…oBar:my-component hello world"
60
+ * ```
61
+ */
62
+ export declare function peerLogger(peerId: PeerId, options?: Partial<PeerLoggerOptions>): ComponentLogger;
63
+ /**
64
+ * Create a component logger that will prefix any log messages with the passed
65
+ * string.
66
+ *
67
+ * @example
68
+ *
69
+ * ```TypeScript
70
+ * import { prefixLogger } from '@libp2p/logger'
71
+ *
72
+ * const logger = prefixLogger('my-node')
73
+ *
74
+ * const log = logger.forComponent('my-component')
75
+ * log.info('hello world')
76
+ * // logs "my-node:my-component hello world"
77
+ * ```
78
+ */
79
+ export declare function prefixLogger(prefix: string): ComponentLogger;
80
+ /**
81
+ * Create a component logger
82
+ *
83
+ * @example
84
+ *
85
+ * ```TypeScript
86
+ * import { defaultLogger } from '@libp2p/logger'
87
+ * import { peerIdFromString } from '@libp2p/peer-id'
88
+ *
89
+ * const logger = defaultLogger()
90
+ *
91
+ * const log = logger.forComponent('my-component')
92
+ * log.info('hello world')
93
+ * // logs "my-component hello world"
94
+ * ```
95
+ */
96
+ export declare function defaultLogger(): ComponentLogger;
97
+ /**
98
+ * Creates a logger for the passed component name.
99
+ *
100
+ * @example
101
+ *
102
+ * ```TypeScript
103
+ * import { logger } from '@libp2p/logger'
104
+ *
105
+ * const log = logger('my-component')
106
+ * log.info('hello world')
107
+ * // logs "my-component hello world"
108
+ * ```
109
+ */
37
110
  export declare function logger(name: string): Logger;
38
111
  export declare function disable(): void;
39
112
  export declare function enable(namespaces: string): void;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AA8CH,MAAM,WAAW,MAAM;IACrB,CAAC,SAAS,EAAE,GAAG,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAA;IACtC,KAAK,CAAC,SAA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,CAErG;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAAE,MAAM,EAAE,MAAM,GAAG,eAAe,CAM7D;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,aAAa,IAAK,eAAe,CAMhD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,MAAM,CAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAa5C;AAED,wBAAgB,OAAO,IAAK,IAAI,CAE/B;AAED,wBAAgB,MAAM,CAAE,UAAU,EAAE,MAAM,GAAG,IAAI,CAEhD;AAED,wBAAgB,OAAO,CAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAEpD"}
package/dist/src/index.js CHANGED
@@ -1,9 +1,8 @@
1
1
  /**
2
2
  * @packageDocumentation
3
3
  *
4
- * A map that reports it's size to the libp2p [Metrics](https://github.com/libp2p/js-libp2p-interfaces/tree/master/packages/libp2p-interfaces/src/metrics#readme) system.
5
- *
6
- * If metrics are disabled a regular map is used.
4
+ * A logger for libp2p based on the venerable [debug](https://www.npmjs.com/package/debug)
5
+ * module.
7
6
  *
8
7
  * @example
9
8
  *
@@ -32,6 +31,7 @@ import debug from 'debug';
32
31
  import { base32 } from 'multiformats/bases/base32';
33
32
  import { base58btc } from 'multiformats/bases/base58';
34
33
  import { base64 } from 'multiformats/bases/base64';
34
+ import { truncatePeerId } from './utils.js';
35
35
  // Add a formatter for converting to a base58 string
36
36
  debug.formatters.b = (v) => {
37
37
  return v == null ? 'undefined' : base58btc.baseEncode(v);
@@ -71,6 +71,86 @@ function createDisabledLogger(namespace) {
71
71
  logger.extend = () => logger;
72
72
  return logger;
73
73
  }
74
+ /**
75
+ * Create a component logger that will prefix any log messages with a truncated
76
+ * peer id.
77
+ *
78
+ * @example
79
+ *
80
+ * ```TypeScript
81
+ * import { peerLogger } from '@libp2p/logger'
82
+ * import { peerIdFromString } from '@libp2p/peer-id'
83
+ *
84
+ * const peerId = peerIdFromString('12D3FooBar')
85
+ * const logger = peerLogger(peerId)
86
+ *
87
+ * const log = logger.forComponent('my-component')
88
+ * log.info('hello world')
89
+ * // logs "12…oBar:my-component hello world"
90
+ * ```
91
+ */
92
+ export function peerLogger(peerId, options = {}) {
93
+ return prefixLogger(truncatePeerId(peerId, options));
94
+ }
95
+ /**
96
+ * Create a component logger that will prefix any log messages with the passed
97
+ * string.
98
+ *
99
+ * @example
100
+ *
101
+ * ```TypeScript
102
+ * import { prefixLogger } from '@libp2p/logger'
103
+ *
104
+ * const logger = prefixLogger('my-node')
105
+ *
106
+ * const log = logger.forComponent('my-component')
107
+ * log.info('hello world')
108
+ * // logs "my-node:my-component hello world"
109
+ * ```
110
+ */
111
+ export function prefixLogger(prefix) {
112
+ return {
113
+ forComponent(name) {
114
+ return logger(`${prefix}:${name}`);
115
+ }
116
+ };
117
+ }
118
+ /**
119
+ * Create a component logger
120
+ *
121
+ * @example
122
+ *
123
+ * ```TypeScript
124
+ * import { defaultLogger } from '@libp2p/logger'
125
+ * import { peerIdFromString } from '@libp2p/peer-id'
126
+ *
127
+ * const logger = defaultLogger()
128
+ *
129
+ * const log = logger.forComponent('my-component')
130
+ * log.info('hello world')
131
+ * // logs "my-component hello world"
132
+ * ```
133
+ */
134
+ export function defaultLogger() {
135
+ return {
136
+ forComponent(name) {
137
+ return logger(name);
138
+ }
139
+ };
140
+ }
141
+ /**
142
+ * Creates a logger for the passed component name.
143
+ *
144
+ * @example
145
+ *
146
+ * ```TypeScript
147
+ * import { logger } from '@libp2p/logger'
148
+ *
149
+ * const log = logger('my-component')
150
+ * log.info('hello world')
151
+ * // logs "my-component hello world"
152
+ * ```
153
+ */
74
154
  export function logger(name) {
75
155
  // trace logging is a no-op by default
76
156
  let trace = createDisabledLogger(`${name}:trace`);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,KAAK,MAAM,OAAO,CA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,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,IAAI,IAAI,EAAE;QAChH,KAAK,GAAG,KAAK,CAAC,GAAG,IAAI,QAAQ,CAAC,CAAA;KAC/B;IAED,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE;QAChC,KAAK,EAAE,KAAK,CAAC,GAAG,IAAI,QAAQ,CAAC;QAC7B,KAAK;KACN,CAAC,CAAA;AACJ,CAAC;AAED,MAAM,UAAU,OAAO;IACrB,KAAK,CAAC,OAAO,EAAE,CAAA;AACjB,CAAC;AAED,MAAM,UAAU,MAAM,CAAE,UAAkB;IACxC,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC,CAAA;AAC1B,CAAC;AAED,MAAM,UAAU,OAAO,CAAE,UAAkB;IACzC,OAAO,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;AAClC,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { PeerLoggerOptions } from './index.js';
2
+ import type { PeerId } from '@libp2p/interface/peer-id';
3
+ export declare function truncatePeerId(peerId: PeerId, options?: Partial<PeerLoggerOptions>): string;
4
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AACnD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AAEvD,wBAAgB,cAAc,CAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,OAAO,CAAC,iBAAiB,CAAM,GAAG,MAAM,CAMhG"}
@@ -0,0 +1,7 @@
1
+ export function truncatePeerId(peerId, options = {}) {
2
+ const prefixLength = options.prefixLength ?? 2;
3
+ const suffixLength = options.suffixLength ?? 4;
4
+ const peerIdString = peerId.toString();
5
+ return `${peerIdString.substring(0, prefixLength)}…${peerIdString.substring(peerIdString.length, peerIdString.length - suffixLength)}`;
6
+ }
7
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,cAAc,CAAE,MAAc,EAAE,UAAsC,EAAE;IACtF,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,CAAC,CAAA;IAC9C,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,CAAC,CAAA;IAE9C,MAAM,YAAY,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAA;IACtC,OAAO,GAAG,YAAY,CAAC,SAAS,CAAC,CAAC,EAAE,YAAY,CAAC,IAAI,YAAY,CAAC,SAAS,CAAC,YAAY,CAAC,MAAM,EAAE,YAAY,CAAC,MAAM,GAAG,YAAY,CAAC,EAAE,CAAA;AACxI,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/logger",
3
- "version": "3.0.5",
3
+ "version": "3.1.0-0f5c305af",
4
4
  "description": "A logging component for use in js-libp2p modules",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/libp2p/js-libp2p/tree/master/packages/logger#readme",
@@ -49,14 +49,14 @@
49
49
  "test:electron-main": "aegir test -t electron-main"
50
50
  },
51
51
  "dependencies": {
52
- "@libp2p/interface": "^0.1.5",
52
+ "@libp2p/interface": "0.1.6-0f5c305af",
53
53
  "@multiformats/multiaddr": "^12.1.5",
54
54
  "debug": "^4.3.4",
55
55
  "interface-datastore": "^8.2.0",
56
56
  "multiformats": "^12.0.1"
57
57
  },
58
58
  "devDependencies": {
59
- "@libp2p/peer-id": "^3.0.5",
59
+ "@libp2p/peer-id": "3.0.6-0f5c305af",
60
60
  "@types/debug": "^4.1.7",
61
61
  "aegir": "^41.0.2",
62
62
  "sinon": "^17.0.0",
package/src/index.ts CHANGED
@@ -1,9 +1,8 @@
1
1
  /**
2
2
  * @packageDocumentation
3
3
  *
4
- * A map that reports it's size to the libp2p [Metrics](https://github.com/libp2p/js-libp2p-interfaces/tree/master/packages/libp2p-interfaces/src/metrics#readme) system.
5
- *
6
- * If metrics are disabled a regular map is used.
4
+ * A logger for libp2p based on the venerable [debug](https://www.npmjs.com/package/debug)
5
+ * module.
7
6
  *
8
7
  * @example
9
8
  *
@@ -33,6 +32,7 @@ import debug from 'debug'
33
32
  import { base32 } from 'multiformats/bases/base32'
34
33
  import { base58btc } from 'multiformats/bases/base58'
35
34
  import { base64 } from 'multiformats/bases/base64'
35
+ import { truncatePeerId } from './utils.js'
36
36
  import type { PeerId } from '@libp2p/interface/peer-id'
37
37
  import type { Multiaddr } from '@multiformats/multiaddr'
38
38
  import type { Key } from 'interface-datastore'
@@ -80,6 +80,10 @@ export interface Logger {
80
80
  enabled: boolean
81
81
  }
82
82
 
83
+ export interface ComponentLogger {
84
+ forComponent(name: string): Logger
85
+ }
86
+
83
87
  function createDisabledLogger (namespace: string): debug.Debugger {
84
88
  const logger = (): void => {}
85
89
  logger.enabled = false
@@ -93,6 +97,94 @@ function createDisabledLogger (namespace: string): debug.Debugger {
93
97
  return logger
94
98
  }
95
99
 
100
+ export interface PeerLoggerOptions {
101
+ prefixLength: number
102
+ suffixLength: number
103
+ }
104
+
105
+ /**
106
+ * Create a component logger that will prefix any log messages with a truncated
107
+ * peer id.
108
+ *
109
+ * @example
110
+ *
111
+ * ```TypeScript
112
+ * import { peerLogger } from '@libp2p/logger'
113
+ * import { peerIdFromString } from '@libp2p/peer-id'
114
+ *
115
+ * const peerId = peerIdFromString('12D3FooBar')
116
+ * const logger = peerLogger(peerId)
117
+ *
118
+ * const log = logger.forComponent('my-component')
119
+ * log.info('hello world')
120
+ * // logs "12…oBar:my-component hello world"
121
+ * ```
122
+ */
123
+ export function peerLogger (peerId: PeerId, options: Partial<PeerLoggerOptions> = {}): ComponentLogger {
124
+ return prefixLogger(truncatePeerId(peerId, options))
125
+ }
126
+
127
+ /**
128
+ * Create a component logger that will prefix any log messages with the passed
129
+ * string.
130
+ *
131
+ * @example
132
+ *
133
+ * ```TypeScript
134
+ * import { prefixLogger } from '@libp2p/logger'
135
+ *
136
+ * const logger = prefixLogger('my-node')
137
+ *
138
+ * const log = logger.forComponent('my-component')
139
+ * log.info('hello world')
140
+ * // logs "my-node:my-component hello world"
141
+ * ```
142
+ */
143
+ export function prefixLogger (prefix: string): ComponentLogger {
144
+ return {
145
+ forComponent (name: string) {
146
+ return logger(`${prefix}:${name}`)
147
+ }
148
+ }
149
+ }
150
+
151
+ /**
152
+ * Create a component logger
153
+ *
154
+ * @example
155
+ *
156
+ * ```TypeScript
157
+ * import { defaultLogger } from '@libp2p/logger'
158
+ * import { peerIdFromString } from '@libp2p/peer-id'
159
+ *
160
+ * const logger = defaultLogger()
161
+ *
162
+ * const log = logger.forComponent('my-component')
163
+ * log.info('hello world')
164
+ * // logs "my-component hello world"
165
+ * ```
166
+ */
167
+ export function defaultLogger (): ComponentLogger {
168
+ return {
169
+ forComponent (name: string) {
170
+ return logger(name)
171
+ }
172
+ }
173
+ }
174
+
175
+ /**
176
+ * Creates a logger for the passed component name.
177
+ *
178
+ * @example
179
+ *
180
+ * ```TypeScript
181
+ * import { logger } from '@libp2p/logger'
182
+ *
183
+ * const log = logger('my-component')
184
+ * log.info('hello world')
185
+ * // logs "my-component hello world"
186
+ * ```
187
+ */
96
188
  export function logger (name: string): Logger {
97
189
  // trace logging is a no-op by default
98
190
  let trace: debug.Debugger = createDisabledLogger(`${name}:trace`)
package/src/utils.ts ADDED
@@ -0,0 +1,10 @@
1
+ import type { PeerLoggerOptions } from './index.js'
2
+ import type { PeerId } from '@libp2p/interface/peer-id'
3
+
4
+ export function truncatePeerId (peerId: PeerId, options: Partial<PeerLoggerOptions> = {}): string {
5
+ const prefixLength = options.prefixLength ?? 2
6
+ const suffixLength = options.suffixLength ?? 4
7
+
8
+ const peerIdString = peerId.toString()
9
+ return `${peerIdString.substring(0, prefixLength)}…${peerIdString.substring(peerIdString.length, peerIdString.length - suffixLength)}`
10
+ }
@@ -1,12 +0,0 @@
1
- {
2
- "Logger": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_logger.Logger.html",
3
- ".:Logger": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_logger.Logger.html",
4
- "disable": "https://libp2p.github.io/js-libp2p/functions/_libp2p_logger.disable.html",
5
- ".:disable": "https://libp2p.github.io/js-libp2p/functions/_libp2p_logger.disable.html",
6
- "enable": "https://libp2p.github.io/js-libp2p/functions/_libp2p_logger.enable.html",
7
- ".:enable": "https://libp2p.github.io/js-libp2p/functions/_libp2p_logger.enable.html",
8
- "enabled": "https://libp2p.github.io/js-libp2p/functions/_libp2p_logger.enabled.html",
9
- ".:enabled": "https://libp2p.github.io/js-libp2p/functions/_libp2p_logger.enabled.html",
10
- "logger": "https://libp2p.github.io/js-libp2p/functions/_libp2p_logger.logger-1.html",
11
- ".:logger": "https://libp2p.github.io/js-libp2p/functions/_libp2p_logger.logger-1.html"
12
- }