@ribbon-studios/logger 3.0.0 → 3.0.1
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.cjs +1 -5
- package/dist/index.js +63 -397
- package/package.json +16 -16
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1 @@
|
|
|
1
|
-
|
|
2
|
-
`:`
|
|
3
|
-
`)+r,n=o+1,o=t.indexOf(`
|
|
4
|
-
`,n)}while(o!==-1);return i+=t.slice(n),i}const{stdout:N,stderr:k}=W,v=Symbol("GENERATOR"),u=Symbol("STYLER"),g=Symbol("IS_EMPTY"),F=["ansi","ansi","ansi256","ansi16m"],h=Object.create(null),D=(t,e={})=>{if(e.level&&!(Number.isInteger(e.level)&&e.level>=0&&e.level<=3))throw new Error("The `level` option should be an integer from 0 to 3");const r=N?N.level:0;t.level=e.level===void 0?r:e.level},K=t=>{const e=(...r)=>r.join(" ");return D(e,t),Object.setPrototypeOf(e,d.prototype),e};function d(t){return K(t)}Object.setPrototypeOf(d.prototype,Function.prototype);for(const[t,e]of Object.entries(a))h[t]={get(){const r=y(this,O(e.open,e.close,this[u]),this[g]);return Object.defineProperty(this,t,{value:r}),r}};h.visible={get(){const t=y(this,this[u],!0);return Object.defineProperty(this,"visible",{value:t}),t}};const A=(t,e,r,...o)=>t==="rgb"?e==="ansi16m"?a[r].ansi16m(...o):e==="ansi256"?a[r].ansi256(a.rgbToAnsi256(...o)):a[r].ansi(a.rgbToAnsi(...o)):t==="hex"?A("rgb",e,r,...a.hexToRgb(...o)):a[r][t](...o),U=["rgb","hex","ansi256"];for(const t of U){h[t]={get(){const{level:r}=this;return function(...o){const n=O(A(t,F[r],"color",...o),a.color.close,this[u]);return y(this,n,this[g])}}};const e="bg"+t[0].toUpperCase()+t.slice(1);h[e]={get(){const{level:r}=this;return function(...o){const n=O(A(t,F[r],"bgColor",...o),a.bgColor.close,this[u]);return y(this,n,this[g])}}}}const X=Object.defineProperties(()=>{},{...h,level:{enumerable:!0,get(){return this[v].level},set(t){this[v].level=t}}}),O=(t,e,r)=>{let o,n;return r===void 0?(o=t,n=e):(o=r.openAll+t,n=e+r.closeAll),{open:t,close:e,openAll:o,closeAll:n,parent:r}},y=(t,e,r)=>{const o=(...n)=>_(o,n.length===1?""+n[0]:n.join(" "));return Object.setPrototypeOf(o,X),o[v]=t,o[u]=e,o[g]=r,o},_=(t,e)=>{if(t.level<=0||!e)return t[g]?"":e;let r=t[u];if(r===void 0)return e;const{openAll:o,closeAll:n}=r;if(e.includes("\x1B"))for(;r!==void 0;)e=H(e,r.close,r.open),r=r.parent;const i=e.indexOf(`
|
|
5
|
-
`);return i!==-1&&(e=V(e,n,o,i)),o+e+n};Object.defineProperties(d.prototype,h);const f=d();d({level:k?k.level:0});function z(t){const e=new Set;return JSON.stringify(t,(r,o)=>{if(typeof o=="object"&&o!==null){if(e.has(o))return;e.add(o)}return o},4)}function J(t){return t.map(e=>e instanceof Error||typeof e!="object"?e:z(e))}var p=(t=>(t[t.ERROR=0]="ERROR",t[t.WARN=1]="WARN",t[t.INFO=2]="INFO",t[t.SILLY=3]="SILLY",t))(p||{});const I=Object.keys(p).reduce((t,e)=>Math.max(t,e.length),0)+3,L={0:f.red,1:f.yellow,2:f.cyan,3:f.magenta};var c;class P{constructor(e){C(this,c);if(j(this,c,{level:2,...typeof e=="string"?{scope:e}:e}),b(this,c).scope){const r=f.rgb(Math.floor(Math.random()*255),Math.floor(Math.random()*255),Math.floor(Math.random()*255));this.prefix=r(`[${b(this,c).scope}]`)}}isLevel(e){return e!=null&&b(this,c).level>=e}isNotLevel(e){return!this.isLevel(e)}setLevel(e){b(this,c).level=e}log(e,...r){if(this.isNotLevel(e))return;const o=L[e],n=J(r).map(s=>s instanceof Error?s:o(s)),i=[this.prefix,o(`[${p[e].toLowerCase()}]:`).padEnd(I," ")].filter(Boolean).join("");console.log(i,...n)}error(...e){this.log(0,...e)}warn(...e){this.log(1,...e)}info(...e){this.log(2,...e)}silly(...e){this.log(3,...e)}}c=new WeakMap;const q=new P;exports.LEVEL_CHALK=L;exports.LogLevel=p;exports.MAX_LENGTH=I;exports.RibbonLogger=P;exports.logger=q;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`chalk`);c=s(c);function l(e){let t=new Set;return JSON.stringify(e,(e,n)=>{if(typeof n==`object`&&n){if(t.has(n))return;t.add(n)}return n},4)}function u(e){return e.map(e=>e instanceof Error||typeof e!=`object`?e:l(e))}var d=function(e){return e[e.ERROR=0]=`ERROR`,e[e.WARN=1]=`WARN`,e[e.INFO=2]=`INFO`,e[e.SILLY=3]=`SILLY`,e}({}),f=Object.keys(d).reduce((e,t)=>Math.max(e,t.length),0)+3,p={[d.ERROR]:c.default.red,[d.WARN]:c.default.yellow,[d.INFO]:c.default.cyan,[d.SILLY]:c.default.magenta},m=class{#e;constructor(e){this.#e={level:d.INFO,...typeof e==`string`?{scope:e}:e},this.#e.scope&&(this.prefix=c.default.rgb(Math.floor(Math.random()*255),Math.floor(Math.random()*255),Math.floor(Math.random()*255))(`[${this.#e.scope}]`))}isLevel(e){return e!=null&&this.#e.level>=e}isNotLevel(e){return!this.isLevel(e)}setLevel(e){this.#e.level=e}log(e,...t){if(this.isNotLevel(e))return;let n=p[e],r=u(t).map(e=>e instanceof Error?e:n(e)),i=[this.prefix,n(`[${d[e].toLowerCase()}]:`).padEnd(f,` `)].filter(Boolean).join(``);console.log(i,...r)}error(...e){this.log(d.ERROR,...e)}warn(...e){this.log(d.WARN,...e)}info(...e){this.log(d.INFO,...e)}silly(...e){this.log(d.SILLY,...e)}},h=new m;exports.LEVEL_CHALK=p,exports.LogLevel=d,exports.MAX_LENGTH=f,exports.RibbonLogger=m,exports.logger=h;
|
package/dist/index.js
CHANGED
|
@@ -1,397 +1,63 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
Object.keys(l.modifier);
|
|
67
|
-
const k = Object.keys(l.color), I = Object.keys(l.bgColor);
|
|
68
|
-
[...k, ...I];
|
|
69
|
-
function P() {
|
|
70
|
-
const t = /* @__PURE__ */ new Map();
|
|
71
|
-
for (const [e, r] of Object.entries(l)) {
|
|
72
|
-
for (const [o, n] of Object.entries(r))
|
|
73
|
-
l[o] = {
|
|
74
|
-
open: `\x1B[${n[0]}m`,
|
|
75
|
-
close: `\x1B[${n[1]}m`
|
|
76
|
-
}, r[o] = l[o], t.set(n[0], n[1]);
|
|
77
|
-
Object.defineProperty(l, e, {
|
|
78
|
-
value: r,
|
|
79
|
-
enumerable: !1
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
return Object.defineProperty(l, "codes", {
|
|
83
|
-
value: t,
|
|
84
|
-
enumerable: !1
|
|
85
|
-
}), l.color.close = "\x1B[39m", l.bgColor.close = "\x1B[49m", l.color.ansi = R(), l.color.ansi256 = S(), l.color.ansi16m = N(), l.bgColor.ansi = R(10), l.bgColor.ansi256 = S(10), l.bgColor.ansi16m = N(10), Object.defineProperties(l, {
|
|
86
|
-
rgbToAnsi256: {
|
|
87
|
-
value(e, r, o) {
|
|
88
|
-
return e === r && r === o ? e < 8 ? 16 : e > 248 ? 231 : Math.round((e - 8) / 247 * 24) + 232 : 16 + 36 * Math.round(e / 255 * 5) + 6 * Math.round(r / 255 * 5) + Math.round(o / 255 * 5);
|
|
89
|
-
},
|
|
90
|
-
enumerable: !1
|
|
91
|
-
},
|
|
92
|
-
hexToRgb: {
|
|
93
|
-
value(e) {
|
|
94
|
-
const r = /[a-f\d]{6}|[a-f\d]{3}/i.exec(e.toString(16));
|
|
95
|
-
if (!r)
|
|
96
|
-
return [0, 0, 0];
|
|
97
|
-
let [o] = r;
|
|
98
|
-
o.length === 3 && (o = [...o].map((s) => s + s).join(""));
|
|
99
|
-
const n = Number.parseInt(o, 16);
|
|
100
|
-
return [
|
|
101
|
-
/* eslint-disable no-bitwise */
|
|
102
|
-
n >> 16 & 255,
|
|
103
|
-
n >> 8 & 255,
|
|
104
|
-
n & 255
|
|
105
|
-
/* eslint-enable no-bitwise */
|
|
106
|
-
];
|
|
107
|
-
},
|
|
108
|
-
enumerable: !1
|
|
109
|
-
},
|
|
110
|
-
hexToAnsi256: {
|
|
111
|
-
value: (e) => l.rgbToAnsi256(...l.hexToRgb(e)),
|
|
112
|
-
enumerable: !1
|
|
113
|
-
},
|
|
114
|
-
ansi256ToAnsi: {
|
|
115
|
-
value(e) {
|
|
116
|
-
if (e < 8)
|
|
117
|
-
return 30 + e;
|
|
118
|
-
if (e < 16)
|
|
119
|
-
return 90 + (e - 8);
|
|
120
|
-
let r, o, n;
|
|
121
|
-
if (e >= 232)
|
|
122
|
-
r = ((e - 232) * 10 + 8) / 255, o = r, n = r;
|
|
123
|
-
else {
|
|
124
|
-
e -= 16;
|
|
125
|
-
const v = e % 36;
|
|
126
|
-
r = Math.floor(e / 36) / 5, o = Math.floor(v / 6) / 5, n = v % 6 / 5;
|
|
127
|
-
}
|
|
128
|
-
const s = Math.max(r, o, n) * 2;
|
|
129
|
-
if (s === 0)
|
|
130
|
-
return 30;
|
|
131
|
-
let i = 30 + (Math.round(n) << 2 | Math.round(o) << 1 | Math.round(r));
|
|
132
|
-
return s === 2 && (i += 60), i;
|
|
133
|
-
},
|
|
134
|
-
enumerable: !1
|
|
135
|
-
},
|
|
136
|
-
rgbToAnsi: {
|
|
137
|
-
value: (e, r, o) => l.ansi256ToAnsi(l.rgbToAnsi256(e, r, o)),
|
|
138
|
-
enumerable: !1
|
|
139
|
-
},
|
|
140
|
-
hexToAnsi: {
|
|
141
|
-
value: (e) => l.ansi256ToAnsi(l.hexToAnsi256(e)),
|
|
142
|
-
enumerable: !1
|
|
143
|
-
}
|
|
144
|
-
}), l;
|
|
145
|
-
}
|
|
146
|
-
const a = P(), j = (() => {
|
|
147
|
-
if (!("navigator" in globalThis))
|
|
148
|
-
return 0;
|
|
149
|
-
if (globalThis.navigator.userAgentData) {
|
|
150
|
-
const t = navigator.userAgentData.brands.find(({ brand: e }) => e === "Chromium");
|
|
151
|
-
if (t && t.version > 93)
|
|
152
|
-
return 3;
|
|
153
|
-
}
|
|
154
|
-
return /\b(Chrome|Chromium)\//.test(globalThis.navigator.userAgent) ? 1 : 0;
|
|
155
|
-
})(), x = j !== 0 && {
|
|
156
|
-
level: j
|
|
157
|
-
}, $ = {
|
|
158
|
-
stdout: x,
|
|
159
|
-
stderr: x
|
|
160
|
-
};
|
|
161
|
-
function G(t, e, r) {
|
|
162
|
-
let o = t.indexOf(e);
|
|
163
|
-
if (o === -1)
|
|
164
|
-
return t;
|
|
165
|
-
const n = e.length;
|
|
166
|
-
let s = 0, i = "";
|
|
167
|
-
do
|
|
168
|
-
i += t.slice(s, o) + e + r, s = o + n, o = t.indexOf(e, s);
|
|
169
|
-
while (o !== -1);
|
|
170
|
-
return i += t.slice(s), i;
|
|
171
|
-
}
|
|
172
|
-
function Y(t, e, r, o) {
|
|
173
|
-
let n = 0, s = "";
|
|
174
|
-
do {
|
|
175
|
-
const i = t[o - 1] === "\r";
|
|
176
|
-
s += t.slice(n, i ? o - 1 : o) + e + (i ? `\r
|
|
177
|
-
` : `
|
|
178
|
-
`) + r, n = o + 1, o = t.indexOf(`
|
|
179
|
-
`, n);
|
|
180
|
-
} while (o !== -1);
|
|
181
|
-
return s += t.slice(n), s;
|
|
182
|
-
}
|
|
183
|
-
const { stdout: E, stderr: w } = $, p = Symbol("GENERATOR"), u = Symbol("STYLER"), g = Symbol("IS_EMPTY"), F = [
|
|
184
|
-
"ansi",
|
|
185
|
-
"ansi",
|
|
186
|
-
"ansi256",
|
|
187
|
-
"ansi16m"
|
|
188
|
-
], h = /* @__PURE__ */ Object.create(null), D = (t, e = {}) => {
|
|
189
|
-
if (e.level && !(Number.isInteger(e.level) && e.level >= 0 && e.level <= 3))
|
|
190
|
-
throw new Error("The `level` option should be an integer from 0 to 3");
|
|
191
|
-
const r = E ? E.level : 0;
|
|
192
|
-
t.level = e.level === void 0 ? r : e.level;
|
|
193
|
-
}, L = (t) => {
|
|
194
|
-
const e = (...r) => r.join(" ");
|
|
195
|
-
return D(e, t), Object.setPrototypeOf(e, d.prototype), e;
|
|
196
|
-
};
|
|
197
|
-
function d(t) {
|
|
198
|
-
return L(t);
|
|
199
|
-
}
|
|
200
|
-
Object.setPrototypeOf(d.prototype, Function.prototype);
|
|
201
|
-
for (const [t, e] of Object.entries(a))
|
|
202
|
-
h[t] = {
|
|
203
|
-
get() {
|
|
204
|
-
const r = y(this, O(e.open, e.close, this[u]), this[g]);
|
|
205
|
-
return Object.defineProperty(this, t, { value: r }), r;
|
|
206
|
-
}
|
|
207
|
-
};
|
|
208
|
-
h.visible = {
|
|
209
|
-
get() {
|
|
210
|
-
const t = y(this, this[u], !0);
|
|
211
|
-
return Object.defineProperty(this, "visible", { value: t }), t;
|
|
212
|
-
}
|
|
213
|
-
};
|
|
214
|
-
const m = (t, e, r, ...o) => t === "rgb" ? e === "ansi16m" ? a[r].ansi16m(...o) : e === "ansi256" ? a[r].ansi256(a.rgbToAnsi256(...o)) : a[r].ansi(a.rgbToAnsi(...o)) : t === "hex" ? m("rgb", e, r, ...a.hexToRgb(...o)) : a[r][t](...o), _ = ["rgb", "hex", "ansi256"];
|
|
215
|
-
for (const t of _) {
|
|
216
|
-
h[t] = {
|
|
217
|
-
get() {
|
|
218
|
-
const { level: r } = this;
|
|
219
|
-
return function(...o) {
|
|
220
|
-
const n = O(m(t, F[r], "color", ...o), a.color.close, this[u]);
|
|
221
|
-
return y(this, n, this[g]);
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
};
|
|
225
|
-
const e = "bg" + t[0].toUpperCase() + t.slice(1);
|
|
226
|
-
h[e] = {
|
|
227
|
-
get() {
|
|
228
|
-
const { level: r } = this;
|
|
229
|
-
return function(...o) {
|
|
230
|
-
const n = O(m(t, F[r], "bgColor", ...o), a.bgColor.close, this[u]);
|
|
231
|
-
return y(this, n, this[g]);
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
const K = Object.defineProperties(() => {
|
|
237
|
-
}, {
|
|
238
|
-
...h,
|
|
239
|
-
level: {
|
|
240
|
-
enumerable: !0,
|
|
241
|
-
get() {
|
|
242
|
-
return this[p].level;
|
|
243
|
-
},
|
|
244
|
-
set(t) {
|
|
245
|
-
this[p].level = t;
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
}), O = (t, e, r) => {
|
|
249
|
-
let o, n;
|
|
250
|
-
return r === void 0 ? (o = t, n = e) : (o = r.openAll + t, n = e + r.closeAll), {
|
|
251
|
-
open: t,
|
|
252
|
-
close: e,
|
|
253
|
-
openAll: o,
|
|
254
|
-
closeAll: n,
|
|
255
|
-
parent: r
|
|
256
|
-
};
|
|
257
|
-
}, y = (t, e, r) => {
|
|
258
|
-
const o = (...n) => U(o, n.length === 1 ? "" + n[0] : n.join(" "));
|
|
259
|
-
return Object.setPrototypeOf(o, K), o[p] = t, o[u] = e, o[g] = r, o;
|
|
260
|
-
}, U = (t, e) => {
|
|
261
|
-
if (t.level <= 0 || !e)
|
|
262
|
-
return t[g] ? "" : e;
|
|
263
|
-
let r = t[u];
|
|
264
|
-
if (r === void 0)
|
|
265
|
-
return e;
|
|
266
|
-
const { openAll: o, closeAll: n } = r;
|
|
267
|
-
if (e.includes("\x1B"))
|
|
268
|
-
for (; r !== void 0; )
|
|
269
|
-
e = G(e, r.close, r.open), r = r.parent;
|
|
270
|
-
const s = e.indexOf(`
|
|
271
|
-
`);
|
|
272
|
-
return s !== -1 && (e = Y(e, n, o, s)), o + e + n;
|
|
273
|
-
};
|
|
274
|
-
Object.defineProperties(d.prototype, h);
|
|
275
|
-
const b = d();
|
|
276
|
-
d({ level: w ? w.level : 0 });
|
|
277
|
-
function W(t) {
|
|
278
|
-
const e = /* @__PURE__ */ new Set();
|
|
279
|
-
return JSON.stringify(
|
|
280
|
-
t,
|
|
281
|
-
(r, o) => {
|
|
282
|
-
if (typeof o == "object" && o !== null) {
|
|
283
|
-
if (e.has(o))
|
|
284
|
-
return;
|
|
285
|
-
e.add(o);
|
|
286
|
-
}
|
|
287
|
-
return o;
|
|
288
|
-
},
|
|
289
|
-
4
|
|
290
|
-
);
|
|
291
|
-
}
|
|
292
|
-
function V(t) {
|
|
293
|
-
return t.map((e) => e instanceof Error || typeof e != "object" ? e : W(e));
|
|
294
|
-
}
|
|
295
|
-
var A = /* @__PURE__ */ ((t) => (t[t.ERROR = 0] = "ERROR", t[t.WARN = 1] = "WARN", t[t.INFO = 2] = "INFO", t[t.SILLY = 3] = "SILLY", t))(A || {});
|
|
296
|
-
const H = Object.keys(A).reduce((t, e) => Math.max(t, e.length), 0) + 3, z = {
|
|
297
|
-
0: b.red,
|
|
298
|
-
1: b.yellow,
|
|
299
|
-
2: b.cyan,
|
|
300
|
-
3: b.magenta
|
|
301
|
-
};
|
|
302
|
-
var c;
|
|
303
|
-
class J {
|
|
304
|
-
constructor(e) {
|
|
305
|
-
C(this, c);
|
|
306
|
-
if (M(this, c, {
|
|
307
|
-
level: 2,
|
|
308
|
-
...typeof e == "string" ? { scope: e } : e
|
|
309
|
-
}), f(this, c).scope) {
|
|
310
|
-
const r = b.rgb(
|
|
311
|
-
Math.floor(Math.random() * 255),
|
|
312
|
-
Math.floor(Math.random() * 255),
|
|
313
|
-
Math.floor(Math.random() * 255)
|
|
314
|
-
);
|
|
315
|
-
this.prefix = r(`[${f(this, c).scope}]`);
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
/**
|
|
319
|
-
* Returns whether the logger is configured to allow the given log level to output.
|
|
320
|
-
* @param level the level to validate
|
|
321
|
-
* @returns true if the given level is equal to or higher priority then the configured level
|
|
322
|
-
*
|
|
323
|
-
* @example
|
|
324
|
-
* Logger.setLevel(LogLevel.INFO);
|
|
325
|
-
* // Returns true
|
|
326
|
-
* Logger.isLevel(LogLevel.ERROR);
|
|
327
|
-
* // Also returns true
|
|
328
|
-
* Logger.isLevel(LogLevel.INFO);
|
|
329
|
-
*/
|
|
330
|
-
isLevel(e) {
|
|
331
|
-
return e != null && f(this, c).level >= e;
|
|
332
|
-
}
|
|
333
|
-
/**
|
|
334
|
-
* Returns whether the logger is configured to deny the given log level to output.
|
|
335
|
-
* @param level the level to validate
|
|
336
|
-
* @returns true if the given level is lower priority then the configured level
|
|
337
|
-
*/
|
|
338
|
-
isNotLevel(e) {
|
|
339
|
-
return !this.isLevel(e);
|
|
340
|
-
}
|
|
341
|
-
/**
|
|
342
|
-
* Sets the level to allow to output
|
|
343
|
-
* @param level the level to set
|
|
344
|
-
*/
|
|
345
|
-
setLevel(e) {
|
|
346
|
-
f(this, c).level = e;
|
|
347
|
-
}
|
|
348
|
-
/**
|
|
349
|
-
* A wrapper around console.log with color formatting and filtering by the set LogLevel.
|
|
350
|
-
* @param level the LogLevel of this message
|
|
351
|
-
* @param rawMessages the messages to send
|
|
352
|
-
*/
|
|
353
|
-
log(e, ...r) {
|
|
354
|
-
if (this.isNotLevel(e)) return;
|
|
355
|
-
const o = z[e], n = V(r).map(
|
|
356
|
-
(i) => i instanceof Error ? i : o(i)
|
|
357
|
-
), s = [this.prefix, o(`[${A[e].toLowerCase()}]:`).padEnd(H, " ")].filter(Boolean).join("");
|
|
358
|
-
console.log(s, ...n);
|
|
359
|
-
}
|
|
360
|
-
/**
|
|
361
|
-
* A helper that automatically calls {@link Logger.log} with {@link LogLevel.ERROR}
|
|
362
|
-
* @param messages the messages to send
|
|
363
|
-
*/
|
|
364
|
-
error(...e) {
|
|
365
|
-
this.log(0, ...e);
|
|
366
|
-
}
|
|
367
|
-
/**
|
|
368
|
-
* A helper that automatically calls {@link Logger.log} with {@link LogLevel.WARN}
|
|
369
|
-
* @param messages the messages to send
|
|
370
|
-
*/
|
|
371
|
-
warn(...e) {
|
|
372
|
-
this.log(1, ...e);
|
|
373
|
-
}
|
|
374
|
-
/**
|
|
375
|
-
* A helper that automatically calls {@link Logger.log} with {@link LogLevel.INFO}
|
|
376
|
-
* @param messages the messages to send
|
|
377
|
-
*/
|
|
378
|
-
info(...e) {
|
|
379
|
-
this.log(2, ...e);
|
|
380
|
-
}
|
|
381
|
-
/**
|
|
382
|
-
* A helper that automatically calls {@link Logger.log} with {@link LogLevel.SILLY}
|
|
383
|
-
* @param messages the messages to send
|
|
384
|
-
*/
|
|
385
|
-
silly(...e) {
|
|
386
|
-
this.log(3, ...e);
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
c = new WeakMap();
|
|
390
|
-
const q = new J();
|
|
391
|
-
export {
|
|
392
|
-
z as LEVEL_CHALK,
|
|
393
|
-
A as LogLevel,
|
|
394
|
-
H as MAX_LENGTH,
|
|
395
|
-
J as RibbonLogger,
|
|
396
|
-
q as logger
|
|
397
|
-
};
|
|
1
|
+
import e from "chalk";
|
|
2
|
+
//#region src/utils/stringify.ts
|
|
3
|
+
function t(e) {
|
|
4
|
+
let t = /* @__PURE__ */ new Set();
|
|
5
|
+
return JSON.stringify(e, (e, n) => {
|
|
6
|
+
if (typeof n == "object" && n) {
|
|
7
|
+
if (t.has(n)) return;
|
|
8
|
+
t.add(n);
|
|
9
|
+
}
|
|
10
|
+
return n;
|
|
11
|
+
}, 4);
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/utils/messages.ts
|
|
15
|
+
function n(e) {
|
|
16
|
+
return e.map((e) => e instanceof Error || typeof e != "object" ? e : t(e));
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/logger.ts
|
|
20
|
+
var r = /* @__PURE__ */ function(e) {
|
|
21
|
+
return e[e.ERROR = 0] = "ERROR", e[e.WARN = 1] = "WARN", e[e.INFO = 2] = "INFO", e[e.SILLY = 3] = "SILLY", e;
|
|
22
|
+
}({}), i = Object.keys(r).reduce((e, t) => Math.max(e, t.length), 0) + 3, a = {
|
|
23
|
+
[r.ERROR]: e.red,
|
|
24
|
+
[r.WARN]: e.yellow,
|
|
25
|
+
[r.INFO]: e.cyan,
|
|
26
|
+
[r.SILLY]: e.magenta
|
|
27
|
+
}, o = class {
|
|
28
|
+
#e;
|
|
29
|
+
constructor(t) {
|
|
30
|
+
this.#e = {
|
|
31
|
+
level: r.INFO,
|
|
32
|
+
...typeof t == "string" ? { scope: t } : t
|
|
33
|
+
}, this.#e.scope && (this.prefix = e.rgb(Math.floor(Math.random() * 255), Math.floor(Math.random() * 255), Math.floor(Math.random() * 255))(`[${this.#e.scope}]`));
|
|
34
|
+
}
|
|
35
|
+
isLevel(e) {
|
|
36
|
+
return e != null && this.#e.level >= e;
|
|
37
|
+
}
|
|
38
|
+
isNotLevel(e) {
|
|
39
|
+
return !this.isLevel(e);
|
|
40
|
+
}
|
|
41
|
+
setLevel(e) {
|
|
42
|
+
this.#e.level = e;
|
|
43
|
+
}
|
|
44
|
+
log(e, ...t) {
|
|
45
|
+
if (this.isNotLevel(e)) return;
|
|
46
|
+
let o = a[e], s = n(t).map((e) => e instanceof Error ? e : o(e)), c = [this.prefix, o(`[${r[e].toLowerCase()}]:`).padEnd(i, " ")].filter(Boolean).join("");
|
|
47
|
+
console.log(c, ...s);
|
|
48
|
+
}
|
|
49
|
+
error(...e) {
|
|
50
|
+
this.log(r.ERROR, ...e);
|
|
51
|
+
}
|
|
52
|
+
warn(...e) {
|
|
53
|
+
this.log(r.WARN, ...e);
|
|
54
|
+
}
|
|
55
|
+
info(...e) {
|
|
56
|
+
this.log(r.INFO, ...e);
|
|
57
|
+
}
|
|
58
|
+
silly(...e) {
|
|
59
|
+
this.log(r.SILLY, ...e);
|
|
60
|
+
}
|
|
61
|
+
}, s = new o();
|
|
62
|
+
//#endregion
|
|
63
|
+
export { a as LEVEL_CHALK, r as LogLevel, i as MAX_LENGTH, o as RibbonLogger, s as logger };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ribbon-studios/logger",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A simple logger for all Ribbon Studios Apps & Libraries",
|
|
6
6
|
"source": "src/index.ts",
|
|
@@ -14,23 +14,23 @@
|
|
|
14
14
|
"test:coverage": "vitest --coverage"
|
|
15
15
|
},
|
|
16
16
|
"peerDependencies": {
|
|
17
|
-
"chalk": "
|
|
17
|
+
"chalk": "^5.4.1"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@types/chance": "^1.1.
|
|
21
|
-
"@types/node": "^22.
|
|
22
|
-
"@vitest/coverage-v8": "
|
|
23
|
-
"ajv": "^8.
|
|
24
|
-
"chance": "^1.1.
|
|
25
|
-
"dedent": "^1.
|
|
26
|
-
"eslint-plugin-unused-imports": "^4.1
|
|
27
|
-
"jiti": "^2.
|
|
28
|
-
"string-dedent": "^3.0.
|
|
29
|
-
"typescript": "^5.
|
|
30
|
-
"typescript-eslint": "^8.
|
|
31
|
-
"vite": "^
|
|
32
|
-
"vite-plugin-dts": "^4.5.
|
|
33
|
-
"vitest": "^
|
|
20
|
+
"@types/chance": "^1.1.7",
|
|
21
|
+
"@types/node": "^22.19.15",
|
|
22
|
+
"@vitest/coverage-v8": "4.1.0",
|
|
23
|
+
"ajv": "^8.18.0",
|
|
24
|
+
"chance": "^1.1.13",
|
|
25
|
+
"dedent": "^1.7.2",
|
|
26
|
+
"eslint-plugin-unused-imports": "^4.4.1",
|
|
27
|
+
"jiti": "^2.6.1",
|
|
28
|
+
"string-dedent": "^3.0.2",
|
|
29
|
+
"typescript": "^5.9.3",
|
|
30
|
+
"typescript-eslint": "^8.57.0",
|
|
31
|
+
"vite": "^8.0.0",
|
|
32
|
+
"vite-plugin-dts": "^4.5.4",
|
|
33
|
+
"vitest": "^4.1.0"
|
|
34
34
|
},
|
|
35
35
|
"publishConfig": {
|
|
36
36
|
"access": "public"
|