@reliverse/relinka 1.4.5 → 1.4.7
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/bin/impl.d.ts +1 -1
- package/bin/impl.js +8 -2
- package/bin/mod.d.ts +0 -22
- package/bin/mod.js +0 -50
- package/package.json +17 -17
- package/bin/deprecated/components/levels/levels.d.ts +0 -13
- package/bin/deprecated/components/levels/levels.js +0 -68
- package/bin/deprecated/components/modes/basic.d.ts +0 -19
- package/bin/deprecated/components/modes/basic.js +0 -20
- package/bin/deprecated/components/modes/browser.d.ts +0 -19
- package/bin/deprecated/components/modes/browser.js +0 -13
- package/bin/deprecated/components/modes/shared.d.ts +0 -2
- package/bin/deprecated/components/modes/shared.js +0 -1
- package/bin/deprecated/components/relinka-deprecated/logger.d.ts +0 -5
- package/bin/deprecated/components/relinka-deprecated/logger.js +0 -5
- package/bin/deprecated/components/relinka-deprecated/mod.d.ts +0 -20
- package/bin/deprecated/components/relinka-deprecated/mod.js +0 -33
- package/bin/deprecated/components/relinka-deprecated/relinka.d.ts +0 -140
- package/bin/deprecated/components/relinka-deprecated/relinka.js +0 -381
- package/bin/deprecated/components/reporters/basic.d.ts +0 -11
- package/bin/deprecated/components/reporters/basic.js +0 -53
- package/bin/deprecated/components/reporters/browser.d.ts +0 -10
- package/bin/deprecated/components/reporters/browser.js +0 -56
- package/bin/deprecated/components/reporters/fancy.d.ts +0 -10
- package/bin/deprecated/components/reporters/fancy.js +0 -104
- package/bin/deprecated/impl-old.d.ts +0 -0
- package/bin/deprecated/impl-old.js +0 -0
- package/bin/deprecated/types.d.ts +0 -161
- package/bin/deprecated/types.js +0 -0
- package/bin/deprecated/utils/box.d.ts +0 -114
- package/bin/deprecated/utils/box.js +0 -145
- package/bin/deprecated/utils/deprecatedColors.d.ts +0 -69
- package/bin/deprecated/utils/deprecatedColors.js +0 -78
- package/bin/deprecated/utils/error.d.ts +0 -6
- package/bin/deprecated/utils/error.js +0 -6
- package/bin/deprecated/utils/format-new.d.ts +0 -15
- package/bin/deprecated/utils/format-new.js +0 -13
- package/bin/deprecated/utils/format.d.ts +0 -14
- package/bin/deprecated/utils/format.js +0 -26
- package/bin/deprecated/utils/log.d.ts +0 -13
- package/bin/deprecated/utils/log.js +0 -15
- package/bin/deprecated/utils/stream.d.ts +0 -14
- package/bin/deprecated/utils/stream.js +0 -4
- package/bin/deprecated/utils/string.d.ts +0 -50
- package/bin/deprecated/utils/string.js +0 -53
- package/bin/deprecated/utils/tree.d.ts +0 -41
- package/bin/deprecated/utils/tree.js +0 -37
|
@@ -1,381 +0,0 @@
|
|
|
1
|
-
import { defu } from "defu";
|
|
2
|
-
import { LogTypesDeprecated } from "../modes/shared.js";
|
|
3
|
-
import { isLogObj } from "../../utils/log.js";
|
|
4
|
-
export class RelinkaInterface {
|
|
5
|
-
options;
|
|
6
|
-
_lastLog;
|
|
7
|
-
// Instance properties for paused state and queue
|
|
8
|
-
_paused;
|
|
9
|
-
_queue;
|
|
10
|
-
_mockFn;
|
|
11
|
-
/**
|
|
12
|
-
* Creates an instance of Relinka with specified options or defaults.
|
|
13
|
-
*
|
|
14
|
-
* @param {Partial<RelinkaOptionsDeprecated>} [options={}] - Configuration options for the Relinka instance.
|
|
15
|
-
*/
|
|
16
|
-
constructor(options = {}) {
|
|
17
|
-
const types = options.types || LogTypesDeprecated;
|
|
18
|
-
this.options = defu(
|
|
19
|
-
{
|
|
20
|
-
...options,
|
|
21
|
-
defaults: { ...options.defaults },
|
|
22
|
-
level: _normalizeLogLevelDeprecated(options.level, types),
|
|
23
|
-
reporters: [...options.reporters || []]
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
types: LogTypesDeprecated,
|
|
27
|
-
throttle: 1e3,
|
|
28
|
-
throttleMin: 5,
|
|
29
|
-
formatOptions: {
|
|
30
|
-
date: true,
|
|
31
|
-
colors: false,
|
|
32
|
-
compact: true
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
);
|
|
36
|
-
for (const type in types) {
|
|
37
|
-
const defaults = {
|
|
38
|
-
type,
|
|
39
|
-
...this.options.defaults,
|
|
40
|
-
...types[type]
|
|
41
|
-
};
|
|
42
|
-
this[type] = this._wrapLogFn(defaults);
|
|
43
|
-
this[type].raw = this._wrapLogFn(defaults, true);
|
|
44
|
-
}
|
|
45
|
-
if (this.options.mockFn) {
|
|
46
|
-
this.mockTypes();
|
|
47
|
-
}
|
|
48
|
-
this._lastLog = {};
|
|
49
|
-
this._paused = false;
|
|
50
|
-
this._queue = [];
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Gets the current log level of the Relinka instance.
|
|
54
|
-
*
|
|
55
|
-
* @returns {number} The current log level.
|
|
56
|
-
*/
|
|
57
|
-
get level() {
|
|
58
|
-
return this.options.level;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Sets the minimum log level that will be output by the instance.
|
|
62
|
-
*
|
|
63
|
-
* @param {number} level - The new log level to set.
|
|
64
|
-
*/
|
|
65
|
-
set level(level) {
|
|
66
|
-
this.options.level = _normalizeLogLevelDeprecated(
|
|
67
|
-
level,
|
|
68
|
-
this.options.types,
|
|
69
|
-
this.options.level
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Creates a new instance of Relinka, inheriting options from the current instance, with possible overrides.
|
|
74
|
-
*
|
|
75
|
-
* @param {Partial<RelinkaOptionsDeprecated>} options - Optional overrides for the new instance. See {@link RelinkaOptionsDeprecated}.
|
|
76
|
-
* @returns {RelinkaInstanceDeprecated} A new Relinka instance. See {@link RelinkaInstanceDeprecated}.
|
|
77
|
-
*/
|
|
78
|
-
create(options) {
|
|
79
|
-
const instance = new RelinkaInterface({
|
|
80
|
-
...this.options,
|
|
81
|
-
...options
|
|
82
|
-
});
|
|
83
|
-
if (this._mockFn) {
|
|
84
|
-
instance.mockTypes(this._mockFn);
|
|
85
|
-
}
|
|
86
|
-
return instance;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Creates a new Relinka instance with the specified default log object properties.
|
|
90
|
-
*
|
|
91
|
-
* @param {InputLogObject} defaults - Default properties to include in any log from the new instance. See {@link InputLogObject}.
|
|
92
|
-
* @returns {RelinkaInstanceDeprecated} A new Relinka instance. See {@link RelinkaInstanceDeprecated}.
|
|
93
|
-
*/
|
|
94
|
-
withDefaults(defaults) {
|
|
95
|
-
return this.create({
|
|
96
|
-
...this.options,
|
|
97
|
-
defaults: {
|
|
98
|
-
...this.options.defaults,
|
|
99
|
-
...defaults
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Creates a new Relinka instance with a specified tag, which will be included in every log.
|
|
105
|
-
*
|
|
106
|
-
* @param {string} tag - The tag to include in each log of the new instance.
|
|
107
|
-
* @returns {RelinkaInstanceDeprecated} A new Relinka instance. See {@link RelinkaInstanceDeprecated}.
|
|
108
|
-
*/
|
|
109
|
-
withTag(tag) {
|
|
110
|
-
return this.withDefaults({
|
|
111
|
-
tag: this.options.defaults.tag ? `${this.options.defaults.tag}:${tag}` : tag
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Adds a custom reporter to the Relinka instance.
|
|
116
|
-
* Reporters will be called for each log message, depending on their implementation and log level.
|
|
117
|
-
*
|
|
118
|
-
* @param {RelinkaReporterDeprecated} reporter - The reporter to add. See {@link RelinkaReporterDeprecated}.
|
|
119
|
-
* @returns {Relinka} The current Relinka instance.
|
|
120
|
-
*/
|
|
121
|
-
addReporter(reporter) {
|
|
122
|
-
this.options.reporters.push(reporter);
|
|
123
|
-
return this;
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Removes a custom reporter from the Relinka instance.
|
|
127
|
-
* If no reporter is specified, all reporters will be removed.
|
|
128
|
-
*
|
|
129
|
-
* @param {RelinkaReporterDeprecated} reporter - The reporter to remove. See {@link RelinkaReporterDeprecated}.
|
|
130
|
-
* @returns {Relinka} The current Relinka instance.
|
|
131
|
-
*/
|
|
132
|
-
removeReporter(reporter) {
|
|
133
|
-
if (reporter) {
|
|
134
|
-
const i = this.options.reporters.indexOf(reporter);
|
|
135
|
-
if (i >= 0) {
|
|
136
|
-
return this.options.reporters.splice(i, 1);
|
|
137
|
-
}
|
|
138
|
-
} else {
|
|
139
|
-
this.options.reporters.splice(0);
|
|
140
|
-
}
|
|
141
|
-
return this;
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Replaces all reporters of the Relinka instance with the specified array of reporters.
|
|
145
|
-
*
|
|
146
|
-
* @param {RelinkaReporterDeprecated[]} reporters - The new reporters to set. See {@link RelinkaReporterDeprecated}.
|
|
147
|
-
* @returns {Relinka} The current Relinka instance.
|
|
148
|
-
*/
|
|
149
|
-
setReporters(reporters) {
|
|
150
|
-
this.options.reporters = Array.isArray(reporters) ? reporters : [reporters];
|
|
151
|
-
return this;
|
|
152
|
-
}
|
|
153
|
-
wrapAll() {
|
|
154
|
-
this.wrapConsole();
|
|
155
|
-
this.wrapStd();
|
|
156
|
-
}
|
|
157
|
-
restoreAll() {
|
|
158
|
-
this.restoreConsole();
|
|
159
|
-
this.restoreStd();
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Overrides console methods with Relinka logging methods for consistent logging.
|
|
163
|
-
*/
|
|
164
|
-
wrapConsole() {
|
|
165
|
-
for (const type in this.options.types) {
|
|
166
|
-
if (!console[`__${type}`]) {
|
|
167
|
-
console[`__${type}`] = console[type];
|
|
168
|
-
}
|
|
169
|
-
console[type] = this[type].raw;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* Restores the original console methods, removing Relinka overrides.
|
|
174
|
-
*/
|
|
175
|
-
restoreConsole() {
|
|
176
|
-
for (const type in this.options.types) {
|
|
177
|
-
if (console[`__${type}`]) {
|
|
178
|
-
console[type] = console[`__${type}`];
|
|
179
|
-
delete console[`__${type}`];
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Overrides standard output and error streams to redirect them through RelinkaInterface.
|
|
185
|
-
*/
|
|
186
|
-
wrapStd() {
|
|
187
|
-
this._wrapStream(this.options.stdout, "log");
|
|
188
|
-
this._wrapStream(this.options.stderr, "log");
|
|
189
|
-
}
|
|
190
|
-
_wrapStream(stream, type) {
|
|
191
|
-
if (!stream) {
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
if (!stream.__write) {
|
|
195
|
-
stream.__write = stream.write;
|
|
196
|
-
}
|
|
197
|
-
stream.write = (data) => {
|
|
198
|
-
this[type].raw(
|
|
199
|
-
String(data).trim()
|
|
200
|
-
);
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* Restores the original standard output and error streams, removing the Relinka redirection.
|
|
205
|
-
*/
|
|
206
|
-
restoreStd() {
|
|
207
|
-
this._restoreStream(this.options.stdout);
|
|
208
|
-
this._restoreStream(this.options.stderr);
|
|
209
|
-
}
|
|
210
|
-
_restoreStream(stream) {
|
|
211
|
-
if (!stream) {
|
|
212
|
-
return;
|
|
213
|
-
}
|
|
214
|
-
if (stream.__write) {
|
|
215
|
-
stream.write = stream.__write;
|
|
216
|
-
stream.__write = void 0;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* Clears the internal state of the Relinka instance.
|
|
221
|
-
* This will reset any throttling, last log data, clear any queued logs,
|
|
222
|
-
* and optionally clear the actual console.
|
|
223
|
-
*
|
|
224
|
-
* @param {boolean} clearConsole - Whether to clear the actual console. Defaults to false.
|
|
225
|
-
*/
|
|
226
|
-
clear(clearConsole = false) {
|
|
227
|
-
this._lastLog = {};
|
|
228
|
-
this._queue = [];
|
|
229
|
-
this._paused = false;
|
|
230
|
-
if (clearConsole && typeof console.clear === "function") {
|
|
231
|
-
console.clear();
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
/**
|
|
235
|
-
* Pauses logging, queues incoming logs until resumed.
|
|
236
|
-
*/
|
|
237
|
-
pauseLogs() {
|
|
238
|
-
this._paused = true;
|
|
239
|
-
}
|
|
240
|
-
/**
|
|
241
|
-
* Resumes logging, processing any queued logs.
|
|
242
|
-
*/
|
|
243
|
-
resumeLogs() {
|
|
244
|
-
this._paused = false;
|
|
245
|
-
const _queue = this._queue.splice(0);
|
|
246
|
-
for (const item of _queue) {
|
|
247
|
-
item[0]._logFn(item[1], item[2]);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
/**
|
|
251
|
-
* Replaces logging methods with mocks if a mock function is provided.
|
|
252
|
-
*
|
|
253
|
-
* @param {RelinkaOptionsDeprecated["mockFn"]} mockFn - The function to use for mocking logging methods. See {@link RelinkaOptionsDeprecated["mockFn"]}.
|
|
254
|
-
*/
|
|
255
|
-
mockTypes(mockFn) {
|
|
256
|
-
const _mockFn = mockFn || this.options.mockFn;
|
|
257
|
-
this._mockFn = _mockFn;
|
|
258
|
-
if (typeof _mockFn !== "function") {
|
|
259
|
-
return;
|
|
260
|
-
}
|
|
261
|
-
for (const type in this.options.types) {
|
|
262
|
-
this[type] = _mockFn(
|
|
263
|
-
type,
|
|
264
|
-
this.options.types[type]
|
|
265
|
-
) || this[type];
|
|
266
|
-
this[type].raw = this[type];
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
// _wrapLogFn uses instances: _paused, _queue, etc
|
|
270
|
-
_wrapLogFn(defaults, isRaw) {
|
|
271
|
-
return (...args) => {
|
|
272
|
-
if (this._paused) {
|
|
273
|
-
this._queue.push([this, defaults, args, isRaw]);
|
|
274
|
-
return false;
|
|
275
|
-
}
|
|
276
|
-
return this._logFn(defaults, args, isRaw);
|
|
277
|
-
};
|
|
278
|
-
}
|
|
279
|
-
_logFn(defaults, args, isRaw) {
|
|
280
|
-
if ((defaults.level || 0) > this.level) {
|
|
281
|
-
return false;
|
|
282
|
-
}
|
|
283
|
-
const logObj = {
|
|
284
|
-
date: /* @__PURE__ */ new Date(),
|
|
285
|
-
args: [],
|
|
286
|
-
...defaults,
|
|
287
|
-
level: _normalizeLogLevelDeprecated(defaults.level, this.options.types)
|
|
288
|
-
};
|
|
289
|
-
if (!isRaw && args.length === 1 && isLogObj(args[0])) {
|
|
290
|
-
Object.assign(logObj, args[0]);
|
|
291
|
-
} else {
|
|
292
|
-
logObj.args = [...args];
|
|
293
|
-
}
|
|
294
|
-
if (logObj.message) {
|
|
295
|
-
logObj.args.unshift(logObj.message);
|
|
296
|
-
logObj.message = void 0;
|
|
297
|
-
}
|
|
298
|
-
if (logObj.additional) {
|
|
299
|
-
if (!Array.isArray(logObj.additional)) {
|
|
300
|
-
logObj.additional = logObj.additional.split("\n");
|
|
301
|
-
}
|
|
302
|
-
logObj.args.push(`
|
|
303
|
-
${logObj.additional.join("\n")}`);
|
|
304
|
-
logObj.additional = void 0;
|
|
305
|
-
}
|
|
306
|
-
logObj.type = typeof logObj.type === "string" ? logObj.type.toLowerCase() : "log";
|
|
307
|
-
logObj.tag = typeof logObj.tag === "string" ? logObj.tag : "";
|
|
308
|
-
const resolveLog = (newLog = false) => {
|
|
309
|
-
const repeated = (this._lastLog.count || 0) - this.options.throttleMin;
|
|
310
|
-
if (this._lastLog.object && repeated > 0) {
|
|
311
|
-
const args2 = [...this._lastLog.object.args];
|
|
312
|
-
if (repeated > 1) {
|
|
313
|
-
args2.push(`(repeated ${repeated} times)`);
|
|
314
|
-
}
|
|
315
|
-
this._log({ ...this._lastLog.object, args: args2 });
|
|
316
|
-
this._lastLog.count = 1;
|
|
317
|
-
}
|
|
318
|
-
if (newLog) {
|
|
319
|
-
this._lastLog.object = logObj;
|
|
320
|
-
this._log(logObj);
|
|
321
|
-
}
|
|
322
|
-
};
|
|
323
|
-
clearTimeout(this._lastLog.timeout);
|
|
324
|
-
const diffTime = this._lastLog.time && logObj.date ? logObj.date.getTime() - this._lastLog.time.getTime() : 0;
|
|
325
|
-
this._lastLog.time = logObj.date;
|
|
326
|
-
if (diffTime < this.options.throttle) {
|
|
327
|
-
try {
|
|
328
|
-
const serializedLog = JSON.stringify([
|
|
329
|
-
logObj.type,
|
|
330
|
-
logObj.tag,
|
|
331
|
-
logObj.args
|
|
332
|
-
]);
|
|
333
|
-
const isSameLog = this._lastLog.serialized === serializedLog;
|
|
334
|
-
this._lastLog.serialized = serializedLog;
|
|
335
|
-
if (isSameLog) {
|
|
336
|
-
this._lastLog.count = (this._lastLog.count || 0) + 1;
|
|
337
|
-
if (this._lastLog.count > this.options.throttleMin) {
|
|
338
|
-
this._lastLog.timeout = setTimeout(
|
|
339
|
-
resolveLog,
|
|
340
|
-
this.options.throttle
|
|
341
|
-
);
|
|
342
|
-
return false;
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
} catch {
|
|
346
|
-
return true;
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
resolveLog(true);
|
|
350
|
-
return true;
|
|
351
|
-
}
|
|
352
|
-
_log(logObj) {
|
|
353
|
-
for (const reporter of this.options.reporters) {
|
|
354
|
-
reporter.log(logObj, {
|
|
355
|
-
options: this.options
|
|
356
|
-
});
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
function _normalizeLogLevelDeprecated(input, types = {}, defaultLevel = 3) {
|
|
361
|
-
if (input === void 0) {
|
|
362
|
-
return defaultLevel;
|
|
363
|
-
}
|
|
364
|
-
if (typeof input === "number") {
|
|
365
|
-
return input;
|
|
366
|
-
}
|
|
367
|
-
if (types[input] && types[input].level !== void 0) {
|
|
368
|
-
return types[input].level;
|
|
369
|
-
}
|
|
370
|
-
return defaultLevel;
|
|
371
|
-
}
|
|
372
|
-
RelinkaInterface.prototype.add = RelinkaInterface.prototype.addReporter;
|
|
373
|
-
RelinkaInterface.prototype.remove = RelinkaInterface.prototype.removeReporter;
|
|
374
|
-
RelinkaInterface.prototype.clear = RelinkaInterface.prototype.removeReporter;
|
|
375
|
-
RelinkaInterface.prototype.withScope = RelinkaInterface.prototype.withTag;
|
|
376
|
-
RelinkaInterface.prototype.mock = RelinkaInterface.prototype.mockTypes;
|
|
377
|
-
RelinkaInterface.prototype.pause = RelinkaInterface.prototype.pauseLogs;
|
|
378
|
-
RelinkaInterface.prototype.resume = RelinkaInterface.prototype.resumeLogs;
|
|
379
|
-
export function createRelinkaDeprecated(options = {}) {
|
|
380
|
-
return new RelinkaInterface(options);
|
|
381
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { LogObject, RelinkaReporterDeprecated, FormatOptions, RelinkaOptionsDeprecated } from "../../types.js";
|
|
2
|
-
export declare class BasicReporter implements RelinkaReporterDeprecated {
|
|
3
|
-
formatStack(stack: string): string;
|
|
4
|
-
formatArgs(args: any[], opts: FormatOptions): string;
|
|
5
|
-
formatDate(date: Date, opts: FormatOptions): string;
|
|
6
|
-
filterAndJoin(arr: any[]): string;
|
|
7
|
-
formatLogObj(logObj: LogObject, opts: FormatOptions): string;
|
|
8
|
-
log(logObj: LogObject, ctx: {
|
|
9
|
-
options: RelinkaOptionsDeprecated;
|
|
10
|
-
}): any;
|
|
11
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { formatWithOptions } from "node:util";
|
|
2
|
-
import { parseStack } from "../../utils/error.js";
|
|
3
|
-
import { writeStream } from "../../utils/stream.js";
|
|
4
|
-
const bracket = (x) => x ? `[${x}]` : "";
|
|
5
|
-
export class BasicReporter {
|
|
6
|
-
formatStack(stack) {
|
|
7
|
-
return ` ${parseStack(stack).join("\n ")}`;
|
|
8
|
-
}
|
|
9
|
-
formatArgs(args, opts) {
|
|
10
|
-
const formattedArgs = args.map((arg) => {
|
|
11
|
-
if (arg && typeof arg.stack === "string") {
|
|
12
|
-
return `${arg.message}
|
|
13
|
-
${this.formatStack(arg.stack)}`;
|
|
14
|
-
}
|
|
15
|
-
return arg;
|
|
16
|
-
});
|
|
17
|
-
return formatWithOptions(opts, ...formattedArgs);
|
|
18
|
-
}
|
|
19
|
-
formatDate(date, opts) {
|
|
20
|
-
return opts.date ? date.toLocaleTimeString() : "";
|
|
21
|
-
}
|
|
22
|
-
filterAndJoin(arr) {
|
|
23
|
-
return arr.filter(Boolean).join(" ");
|
|
24
|
-
}
|
|
25
|
-
formatLogObj(logObj, opts) {
|
|
26
|
-
const message = this.formatArgs(logObj.args, opts);
|
|
27
|
-
if (logObj.type === "box") {
|
|
28
|
-
return `
|
|
29
|
-
${[
|
|
30
|
-
bracket(logObj.tag),
|
|
31
|
-
logObj.title && logObj.title,
|
|
32
|
-
...message.split("\n")
|
|
33
|
-
].filter(Boolean).map((l) => ` > ${l}`).join("\n")}
|
|
34
|
-
`;
|
|
35
|
-
}
|
|
36
|
-
return this.filterAndJoin([
|
|
37
|
-
bracket(logObj.type),
|
|
38
|
-
bracket(logObj.tag),
|
|
39
|
-
message
|
|
40
|
-
]);
|
|
41
|
-
}
|
|
42
|
-
log(logObj, ctx) {
|
|
43
|
-
const line = this.formatLogObj(logObj, {
|
|
44
|
-
columns: ctx.options.stdout.columns || 0,
|
|
45
|
-
...ctx.options.formatOptions
|
|
46
|
-
});
|
|
47
|
-
return writeStream(
|
|
48
|
-
`${line}
|
|
49
|
-
`,
|
|
50
|
-
logObj.level < 2 ? ctx.options.stderr || process.stderr : ctx.options.stdout || process.stdout
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { LogObject } from "../../types.js";
|
|
2
|
-
export declare class BrowserReporter {
|
|
3
|
-
options: any;
|
|
4
|
-
defaultColor: string;
|
|
5
|
-
levelColorMap: Record<number, string>;
|
|
6
|
-
typeColorMap: Record<string, string>;
|
|
7
|
-
constructor(options: any);
|
|
8
|
-
_getLogFn(level: number): any;
|
|
9
|
-
log(logObj: LogObject): void;
|
|
10
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
export class BrowserReporter {
|
|
2
|
-
options;
|
|
3
|
-
defaultColor;
|
|
4
|
-
levelColorMap;
|
|
5
|
-
typeColorMap;
|
|
6
|
-
constructor(options) {
|
|
7
|
-
this.options = { ...options };
|
|
8
|
-
this.defaultColor = "#7f8c8d";
|
|
9
|
-
this.levelColorMap = {
|
|
10
|
-
0: "#c0392b",
|
|
11
|
-
// Red
|
|
12
|
-
1: "#f39c12",
|
|
13
|
-
// Yellow
|
|
14
|
-
3: "#00BCD4"
|
|
15
|
-
// Cyan
|
|
16
|
-
};
|
|
17
|
-
this.typeColorMap = {
|
|
18
|
-
success: "#2ecc71"
|
|
19
|
-
// Green
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
_getLogFn(level) {
|
|
23
|
-
if (level < 1) {
|
|
24
|
-
return console.__error || console.error;
|
|
25
|
-
}
|
|
26
|
-
if (level === 1) {
|
|
27
|
-
return console.__warn || console.warn;
|
|
28
|
-
}
|
|
29
|
-
return console.__log || console.log;
|
|
30
|
-
}
|
|
31
|
-
log(logObj) {
|
|
32
|
-
const consoleLogFn = this._getLogFn(logObj.level);
|
|
33
|
-
const type = logObj.type === "log" ? "" : logObj.type;
|
|
34
|
-
const tag = logObj.tag || "";
|
|
35
|
-
const color = this.typeColorMap[logObj.type] || this.levelColorMap[logObj.level] || this.defaultColor;
|
|
36
|
-
const style = `
|
|
37
|
-
background: ${color};
|
|
38
|
-
border-radius: 0.5em;
|
|
39
|
-
color: white;
|
|
40
|
-
font-weight: bold;
|
|
41
|
-
padding: 2px 0.5em;
|
|
42
|
-
`;
|
|
43
|
-
const badge = `%c${[tag, type].filter(Boolean).join(":")}`;
|
|
44
|
-
if (typeof logObj.args[0] === "string") {
|
|
45
|
-
consoleLogFn(
|
|
46
|
-
`${badge}%c ${logObj.args[0]}`,
|
|
47
|
-
style,
|
|
48
|
-
// Empty string as style resets to default console style
|
|
49
|
-
"",
|
|
50
|
-
...logObj.args.slice(1)
|
|
51
|
-
);
|
|
52
|
-
} else {
|
|
53
|
-
consoleLogFn(badge, style, ...logObj.args);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { LogLevelDeprecated, LogTypeDeprecated } from "../../types.js";
|
|
2
|
-
import type { FormatOptions, LogObject } from "../../types.js";
|
|
3
|
-
import { BasicReporter } from "./basic.js";
|
|
4
|
-
export declare const TYPE_COLOR_MAP: Partial<Record<LogTypeDeprecated, string>>;
|
|
5
|
-
export declare const LEVEL_COLOR_MAP: Partial<Record<LogLevelDeprecated, string>>;
|
|
6
|
-
export declare class FancyReporter extends BasicReporter {
|
|
7
|
-
formatStack(stack: string): string;
|
|
8
|
-
formatType(logObj: LogObject, isBadge: boolean): any;
|
|
9
|
-
formatLogObj(logObj: LogObject, opts: FormatOptions): any;
|
|
10
|
-
}
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { isUnicodeSupported } from "@reliverse/runtime";
|
|
2
|
-
import stringWidth from "string-width";
|
|
3
|
-
import { BasicReporter } from "./basic.js";
|
|
4
|
-
import { box } from "../../utils/box.js";
|
|
5
|
-
import { colors } from "../../utils/deprecatedColors.js";
|
|
6
|
-
import { parseStack } from "../../utils/error.js";
|
|
7
|
-
import { stripAnsi } from "../../utils/string.js";
|
|
8
|
-
export const TYPE_COLOR_MAP = {
|
|
9
|
-
info: "cyan",
|
|
10
|
-
fail: "red",
|
|
11
|
-
success: "green",
|
|
12
|
-
ready: "green",
|
|
13
|
-
start: "magenta"
|
|
14
|
-
};
|
|
15
|
-
export const LEVEL_COLOR_MAP = {
|
|
16
|
-
0: "red",
|
|
17
|
-
1: "yellow"
|
|
18
|
-
};
|
|
19
|
-
const unicode = isUnicodeSupported();
|
|
20
|
-
const s = (c, fallback) => unicode ? c : fallback;
|
|
21
|
-
const TYPE_ICONS = {
|
|
22
|
-
error: s("\u2716", "\xD7"),
|
|
23
|
-
fatal: s("\u2716", "\xD7"),
|
|
24
|
-
ready: s("\u2714", "\u221A"),
|
|
25
|
-
warn: s("\u26A0", "\u203C"),
|
|
26
|
-
info: s("\u2139", "i"),
|
|
27
|
-
success: s("\u2714", "\u221A"),
|
|
28
|
-
debug: s("\u2699", "D"),
|
|
29
|
-
trace: s("\u2192", "\u2192"),
|
|
30
|
-
fail: s("\u2716", "\xD7"),
|
|
31
|
-
start: s("\u25D0", "o"),
|
|
32
|
-
log: ""
|
|
33
|
-
};
|
|
34
|
-
function getStringWidth(str) {
|
|
35
|
-
if (!Intl.Segmenter) {
|
|
36
|
-
return stripAnsi(str).length;
|
|
37
|
-
}
|
|
38
|
-
return stringWidth(str);
|
|
39
|
-
}
|
|
40
|
-
export class FancyReporter extends BasicReporter {
|
|
41
|
-
formatStack(stack) {
|
|
42
|
-
return `
|
|
43
|
-
${parseStack(stack).map(
|
|
44
|
-
(line) => ` ${line.replace(/^at +/, (m) => colors.gray(m)).replace(/\((.+)\)/, (_, m) => `(${colors.cyan(m)})`)}`
|
|
45
|
-
).join("\n")}`;
|
|
46
|
-
}
|
|
47
|
-
formatType(logObj, isBadge) {
|
|
48
|
-
const typeColor = TYPE_COLOR_MAP[logObj.type] || LEVEL_COLOR_MAP[logObj.level] || "gray";
|
|
49
|
-
if (isBadge) {
|
|
50
|
-
return getBgColor(typeColor)(
|
|
51
|
-
colors.black(` ${logObj.type.toUpperCase()} `)
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
const _type = typeof TYPE_ICONS[logObj.type] === "string" ? TYPE_ICONS[logObj.type] : logObj.icon || logObj.type;
|
|
55
|
-
return _type ? getColor(typeColor)(_type) : "";
|
|
56
|
-
}
|
|
57
|
-
formatLogObj(logObj, opts) {
|
|
58
|
-
const [message, ...additional] = this.formatArgs(logObj.args, opts).split(
|
|
59
|
-
"\n"
|
|
60
|
-
);
|
|
61
|
-
if (logObj.type === "box") {
|
|
62
|
-
return box(
|
|
63
|
-
characterFormat(
|
|
64
|
-
message + (additional.length > 0 ? `
|
|
65
|
-
${additional.join("\n")}` : "")
|
|
66
|
-
),
|
|
67
|
-
{
|
|
68
|
-
title: logObj.title ? characterFormat(logObj.title) : void 0,
|
|
69
|
-
style: logObj.style
|
|
70
|
-
}
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
const date = this.formatDate(logObj.date, opts);
|
|
74
|
-
const coloredDate = date && colors.gray(date);
|
|
75
|
-
const isBadge = logObj.badge ?? logObj.level < 2;
|
|
76
|
-
const type = this.formatType(logObj, isBadge);
|
|
77
|
-
const tag = logObj.tag ? colors.gray(logObj.tag) : "";
|
|
78
|
-
let line;
|
|
79
|
-
const left = this.filterAndJoin([type, characterFormat(message)]);
|
|
80
|
-
const right = this.filterAndJoin(opts.columns ? [tag, coloredDate] : [tag]);
|
|
81
|
-
const space = (opts.columns || 0) - getStringWidth(left) - getStringWidth(right) - 2;
|
|
82
|
-
line = space > 0 && (opts.columns || 0) >= 80 ? left + " ".repeat(space) + right : (right ? `${colors.gray(`[${right}]`)} ` : "") + left;
|
|
83
|
-
line += characterFormat(
|
|
84
|
-
additional.length > 0 ? `
|
|
85
|
-
${additional.join("\n")}` : ""
|
|
86
|
-
);
|
|
87
|
-
if (logObj.type === "trace") {
|
|
88
|
-
const _err = new Error(`Trace: ${logObj.message}`);
|
|
89
|
-
line += this.formatStack(_err.stack || "");
|
|
90
|
-
}
|
|
91
|
-
return isBadge ? `
|
|
92
|
-
${line}
|
|
93
|
-
` : line;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
function characterFormat(str) {
|
|
97
|
-
return str.replace(/`([^`]+)`/gm, (_, m) => colors.cyan(m)).replace(/\s+_([^_]+)_\s+/gm, (_, m) => ` ${colors.underline(m)} `);
|
|
98
|
-
}
|
|
99
|
-
function getColor(color = "white") {
|
|
100
|
-
return colors[color] || colors.white;
|
|
101
|
-
}
|
|
102
|
-
function getBgColor(color = "bgWhite") {
|
|
103
|
-
return colors[`bg${color[0].toUpperCase()}${color.slice(1)}`] || colors.bgWhite;
|
|
104
|
-
}
|
|
File without changes
|
|
File without changes
|