@reliverse/relinka 1.2.3 → 1.2.5
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/LICENSE +2 -2
- package/README.md +2 -8
- package/dist-npm/components/levels/levels.d.ts +21 -0
- package/dist-npm/components/levels/levels.js +8 -8
- package/dist-npm/components/messages/mapping.d.ts +3 -0
- package/dist-npm/components/messages/mapping.js +49 -0
- package/dist-npm/components/messages/messages.d.ts +89 -0
- package/dist-npm/components/messages/messages.js +329 -0
- package/dist-npm/components/messages/mod.d.ts +6 -0
- package/dist-npm/components/messages/mod.js +6 -0
- package/dist-npm/components/messages/platforms.d.ts +10 -0
- package/dist-npm/components/messages/platforms.js +67 -0
- package/dist-npm/components/messages/terminal.d.ts +15 -0
- package/dist-npm/components/messages/terminal.js +57 -0
- package/dist-npm/components/messages/types.d.ts +12 -0
- package/dist-npm/components/messages/types.js +0 -0
- package/dist-npm/components/messages/variants.d.ts +12 -0
- package/dist-npm/components/messages/variants.js +52 -0
- package/dist-npm/components/modes/basic.d.ts +14 -2
- package/dist-npm/components/modes/basic.js +6 -6
- package/dist-npm/components/modes/browser.d.ts +16 -2
- package/dist-npm/components/modes/browser.js +5 -5
- package/dist-npm/components/modes/shared.d.ts +1 -1
- package/dist-npm/components/modes/shared.js +1 -1
- package/dist-npm/components/relinka/logger.d.ts +12 -0
- package/dist-npm/components/relinka/logger.js +52 -0
- package/dist-npm/components/relinka/mod.d.ts +21 -0
- package/dist-npm/components/relinka/mod.js +34 -0
- package/dist-npm/components/relinka/relinka.d.ts +118 -20
- package/dist-npm/components/relinka/relinka.js +133 -36
- package/dist-npm/components/reporters/basic.d.ts +1 -1
- package/dist-npm/components/reporters/basic.js +5 -5
- package/dist-npm/components/reporters/browser.js +5 -5
- package/dist-npm/components/reporters/fancy.d.ts +1 -1
- package/dist-npm/components/reporters/fancy.js +9 -9
- package/dist-npm/main.d.ts +3 -8
- package/dist-npm/main.js +3 -34
- package/dist-npm/types/mod.d.ts +136 -29
- package/dist-npm/utils/box.d.ts +104 -14
- package/dist-npm/utils/box.js +1 -1
- package/dist-npm/utils/color.d.ts +20 -0
- package/dist-npm/utils/color.js +3 -3
- package/dist-npm/utils/error.d.ts +5 -0
- package/dist-npm/utils/format.d.ts +12 -0
- package/dist-npm/utils/log.d.ts +11 -0
- package/dist-npm/utils/stream.d.ts +13 -0
- package/dist-npm/utils/string.d.ts +45 -0
- package/dist-npm/utils/tree.d.ts +34 -5
- package/package.json +35 -32
- package/LICENSE.md +0 -21
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
import { defu } from "defu";
|
|
2
2
|
import { LogTypes } from "../../components/levels/levels.js";
|
|
3
3
|
import { isLogObj } from "../../utils/log.js";
|
|
4
|
-
|
|
5
|
-
const queue = [];
|
|
6
|
-
export class Relinka {
|
|
4
|
+
export class RelinkaInterface {
|
|
7
5
|
options;
|
|
8
6
|
_lastLog;
|
|
7
|
+
// Instance properties for paused state and queue
|
|
8
|
+
_paused;
|
|
9
|
+
_queue;
|
|
9
10
|
_mockFn;
|
|
10
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Creates an instance of Relinka with specified options or defaults.
|
|
13
|
+
*
|
|
14
|
+
* @param {Partial<RelinkaOptions>} [options={}] - Configuration options for the Relinka instance.
|
|
15
|
+
*/
|
|
16
|
+
constructor(options = {}) {
|
|
11
17
|
const types = options.types || LogTypes;
|
|
12
18
|
this.options = defu(
|
|
13
19
|
{
|
|
@@ -43,19 +49,37 @@ export class Relinka {
|
|
|
43
49
|
this.mockTypes();
|
|
44
50
|
}
|
|
45
51
|
this._lastLog = {};
|
|
52
|
+
this._paused = false;
|
|
53
|
+
this._queue = [];
|
|
46
54
|
}
|
|
47
|
-
|
|
55
|
+
/**
|
|
56
|
+
* Gets the current log level of the Relinka instance.
|
|
57
|
+
*
|
|
58
|
+
* @returns {number} The current log level.
|
|
59
|
+
*/
|
|
60
|
+
get level() {
|
|
48
61
|
return this.options.level;
|
|
49
62
|
}
|
|
50
|
-
|
|
63
|
+
/**
|
|
64
|
+
* Sets the minimum log level that will be output by the instance.
|
|
65
|
+
*
|
|
66
|
+
* @param {number} level - The new log level to set.
|
|
67
|
+
*/
|
|
68
|
+
set level(level) {
|
|
51
69
|
this.options.level = _normalizeLogLevel(
|
|
52
70
|
level,
|
|
53
71
|
this.options.types,
|
|
54
72
|
this.options.level
|
|
55
73
|
);
|
|
56
74
|
}
|
|
57
|
-
|
|
58
|
-
|
|
75
|
+
/**
|
|
76
|
+
* Creates a new instance of Relinka, inheriting options from the current instance, with possible overrides.
|
|
77
|
+
*
|
|
78
|
+
* @param {Partial<RelinkaOptions>} options - Optional overrides for the new instance. See {@link RelinkaOptions}.
|
|
79
|
+
* @returns {RelinkaInstance} A new Relinka instance. See {@link RelinkaInstance}.
|
|
80
|
+
*/
|
|
81
|
+
create(options) {
|
|
82
|
+
const instance = new RelinkaInterface({
|
|
59
83
|
...this.options,
|
|
60
84
|
...options
|
|
61
85
|
});
|
|
@@ -64,7 +88,13 @@ export class Relinka {
|
|
|
64
88
|
}
|
|
65
89
|
return instance;
|
|
66
90
|
}
|
|
67
|
-
|
|
91
|
+
/**
|
|
92
|
+
* Creates a new Relinka instance with the specified default log object properties.
|
|
93
|
+
*
|
|
94
|
+
* @param {InputLogObject} defaults - Default properties to include in any log from the new instance. See {@link InputLogObject}.
|
|
95
|
+
* @returns {RelinkaInstance} A new Relinka instance. See {@link RelinkaInstance}.
|
|
96
|
+
*/
|
|
97
|
+
withDefaults(defaults) {
|
|
68
98
|
return this.create({
|
|
69
99
|
...this.options,
|
|
70
100
|
defaults: {
|
|
@@ -73,16 +103,36 @@ export class Relinka {
|
|
|
73
103
|
}
|
|
74
104
|
});
|
|
75
105
|
}
|
|
76
|
-
|
|
106
|
+
/**
|
|
107
|
+
* Creates a new Relinka instance with a specified tag, which will be included in every log.
|
|
108
|
+
*
|
|
109
|
+
* @param {string} tag - The tag to include in each log of the new instance.
|
|
110
|
+
* @returns {RelinkaInstance} A new Relinka instance. See {@link RelinkaInstance}.
|
|
111
|
+
*/
|
|
112
|
+
withTag(tag) {
|
|
77
113
|
return this.withDefaults({
|
|
78
114
|
tag: this.options.defaults.tag ? this.options.defaults.tag + ":" + tag : tag
|
|
79
115
|
});
|
|
80
116
|
}
|
|
81
|
-
|
|
117
|
+
/**
|
|
118
|
+
* Adds a custom reporter to the Relinka instance.
|
|
119
|
+
* Reporters will be called for each log message, depending on their implementation and log level.
|
|
120
|
+
*
|
|
121
|
+
* @param {RelinkaReporter} reporter - The reporter to add. See {@link RelinkaReporter}.
|
|
122
|
+
* @returns {Relinka} The current Relinka instance.
|
|
123
|
+
*/
|
|
124
|
+
addReporter(reporter) {
|
|
82
125
|
this.options.reporters.push(reporter);
|
|
83
126
|
return this;
|
|
84
127
|
}
|
|
85
|
-
|
|
128
|
+
/**
|
|
129
|
+
* Removes a custom reporter from the Relinka instance.
|
|
130
|
+
* If no reporter is specified, all reporters will be removed.
|
|
131
|
+
*
|
|
132
|
+
* @param {RelinkaReporter} reporter - The reporter to remove. See {@link RelinkaReporter}.
|
|
133
|
+
* @returns {Relinka} The current Relinka instance.
|
|
134
|
+
*/
|
|
135
|
+
removeReporter(reporter) {
|
|
86
136
|
if (reporter) {
|
|
87
137
|
const i = this.options.reporters.indexOf(reporter);
|
|
88
138
|
if (i >= 0) {
|
|
@@ -93,7 +143,13 @@ export class Relinka {
|
|
|
93
143
|
}
|
|
94
144
|
return this;
|
|
95
145
|
}
|
|
96
|
-
|
|
146
|
+
/**
|
|
147
|
+
* Replaces all reporters of the Relinka instance with the specified array of reporters.
|
|
148
|
+
*
|
|
149
|
+
* @param {RelinkaReporter[]} reporters - The new reporters to set. See {@link RelinkaReporter}.
|
|
150
|
+
* @returns {Relinka} The current Relinka instance.
|
|
151
|
+
*/
|
|
152
|
+
setReporters(reporters) {
|
|
97
153
|
this.options.reporters = Array.isArray(reporters) ? reporters : [reporters];
|
|
98
154
|
return this;
|
|
99
155
|
}
|
|
@@ -105,7 +161,10 @@ export class Relinka {
|
|
|
105
161
|
this.restoreConsole();
|
|
106
162
|
this.restoreStd();
|
|
107
163
|
}
|
|
108
|
-
|
|
164
|
+
/**
|
|
165
|
+
* Overrides console methods with Relinka logging methods for consistent logging.
|
|
166
|
+
*/
|
|
167
|
+
wrapConsole() {
|
|
109
168
|
for (const type in this.options.types) {
|
|
110
169
|
if (!console["__" + type]) {
|
|
111
170
|
console["__" + type] = console[type];
|
|
@@ -113,7 +172,10 @@ export class Relinka {
|
|
|
113
172
|
console[type] = this[type].raw;
|
|
114
173
|
}
|
|
115
174
|
}
|
|
116
|
-
|
|
175
|
+
/**
|
|
176
|
+
* Restores the original console methods, removing Relinka overrides.
|
|
177
|
+
*/
|
|
178
|
+
restoreConsole() {
|
|
117
179
|
for (const type in this.options.types) {
|
|
118
180
|
if (console["__" + type]) {
|
|
119
181
|
console[type] = console["__" + type];
|
|
@@ -121,7 +183,10 @@ export class Relinka {
|
|
|
121
183
|
}
|
|
122
184
|
}
|
|
123
185
|
}
|
|
124
|
-
|
|
186
|
+
/**
|
|
187
|
+
* Overrides standard output and error streams to redirect them through RelinkaInterface.
|
|
188
|
+
*/
|
|
189
|
+
wrapStd() {
|
|
125
190
|
this._wrapStream(this.options.stdout, "log");
|
|
126
191
|
this._wrapStream(this.options.stderr, "log");
|
|
127
192
|
}
|
|
@@ -136,7 +201,10 @@ export class Relinka {
|
|
|
136
201
|
this[type].raw(String(data).trim());
|
|
137
202
|
};
|
|
138
203
|
}
|
|
139
|
-
|
|
204
|
+
/**
|
|
205
|
+
* Restores the original standard output and error streams, removing the Relinka redirection.
|
|
206
|
+
*/
|
|
207
|
+
restoreStd() {
|
|
140
208
|
this._restoreStream(this.options.stdout);
|
|
141
209
|
this._restoreStream(this.options.stderr);
|
|
142
210
|
}
|
|
@@ -149,17 +217,43 @@ export class Relinka {
|
|
|
149
217
|
delete stream.__write;
|
|
150
218
|
}
|
|
151
219
|
}
|
|
152
|
-
|
|
153
|
-
|
|
220
|
+
/**
|
|
221
|
+
* Clears the internal state of the Relinka instance.
|
|
222
|
+
* This will reset any throttling, last log data, clear any queued logs,
|
|
223
|
+
* and optionally clear the actual console.
|
|
224
|
+
*
|
|
225
|
+
* @param {boolean} clearConsole - Whether to clear the actual console. Defaults to false.
|
|
226
|
+
*/
|
|
227
|
+
clear(clearConsole = false) {
|
|
228
|
+
this._lastLog = {};
|
|
229
|
+
this._queue = [];
|
|
230
|
+
this._paused = false;
|
|
231
|
+
if (clearConsole && typeof console.clear === "function") {
|
|
232
|
+
console.clear();
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Pauses logging, queues incoming logs until resumed.
|
|
237
|
+
*/
|
|
238
|
+
pauseLogs() {
|
|
239
|
+
this._paused = true;
|
|
154
240
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
241
|
+
/**
|
|
242
|
+
* Resumes logging, processing any queued logs.
|
|
243
|
+
*/
|
|
244
|
+
resumeLogs() {
|
|
245
|
+
this._paused = false;
|
|
246
|
+
const _queue = this._queue.splice(0);
|
|
158
247
|
for (const item of _queue) {
|
|
159
248
|
item[0]._logFn(item[1], item[2]);
|
|
160
249
|
}
|
|
161
250
|
}
|
|
162
|
-
|
|
251
|
+
/**
|
|
252
|
+
* Replaces logging methods with mocks if a mock function is provided.
|
|
253
|
+
*
|
|
254
|
+
* @param {RelinkaOptions["mockFn"]} mockFn - The function to use for mocking logging methods. See {@link RelinkaOptions["mockFn"]}.
|
|
255
|
+
*/
|
|
256
|
+
mockTypes(mockFn) {
|
|
163
257
|
const _mockFn = mockFn || this.options.mockFn;
|
|
164
258
|
this._mockFn = _mockFn;
|
|
165
259
|
if (typeof _mockFn !== "function") {
|
|
@@ -170,11 +264,12 @@ export class Relinka {
|
|
|
170
264
|
this[type].raw = this[type];
|
|
171
265
|
}
|
|
172
266
|
}
|
|
267
|
+
// _wrapLogFn uses instances: _paused, _queue, etc
|
|
173
268
|
_wrapLogFn(defaults, isRaw) {
|
|
174
269
|
return (...args) => {
|
|
175
|
-
if (
|
|
176
|
-
|
|
177
|
-
return;
|
|
270
|
+
if (this._paused) {
|
|
271
|
+
this._queue.push([this, defaults, args, isRaw]);
|
|
272
|
+
return false;
|
|
178
273
|
}
|
|
179
274
|
return this._logFn(defaults, args, isRaw);
|
|
180
275
|
};
|
|
@@ -184,7 +279,7 @@ export class Relinka {
|
|
|
184
279
|
return false;
|
|
185
280
|
}
|
|
186
281
|
const logObj = {
|
|
187
|
-
date:
|
|
282
|
+
date: /* @__PURE__ */ new Date(),
|
|
188
283
|
args: [],
|
|
189
284
|
...defaults,
|
|
190
285
|
level: _normalizeLogLevel(defaults.level, this.options.types)
|
|
@@ -241,13 +336,15 @@ export class Relinka {
|
|
|
241
336
|
resolveLog,
|
|
242
337
|
this.options.throttle
|
|
243
338
|
);
|
|
244
|
-
return;
|
|
339
|
+
return false;
|
|
245
340
|
}
|
|
246
341
|
}
|
|
247
342
|
} catch {
|
|
343
|
+
return true;
|
|
248
344
|
}
|
|
249
345
|
}
|
|
250
346
|
resolveLog(true);
|
|
347
|
+
return true;
|
|
251
348
|
}
|
|
252
349
|
_log(logObj) {
|
|
253
350
|
for (const reporter of this.options.reporters) {
|
|
@@ -269,13 +366,13 @@ function _normalizeLogLevel(input, types = {}, defaultLevel = 3) {
|
|
|
269
366
|
}
|
|
270
367
|
return defaultLevel;
|
|
271
368
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
369
|
+
RelinkaInterface.prototype.add = RelinkaInterface.prototype.addReporter;
|
|
370
|
+
RelinkaInterface.prototype.remove = RelinkaInterface.prototype.removeReporter;
|
|
371
|
+
RelinkaInterface.prototype.clear = RelinkaInterface.prototype.removeReporter;
|
|
372
|
+
RelinkaInterface.prototype.withScope = RelinkaInterface.prototype.withTag;
|
|
373
|
+
RelinkaInterface.prototype.mock = RelinkaInterface.prototype.mockTypes;
|
|
374
|
+
RelinkaInterface.prototype.pause = RelinkaInterface.prototype.pauseLogs;
|
|
375
|
+
RelinkaInterface.prototype.resume = RelinkaInterface.prototype.resumeLogs;
|
|
279
376
|
export function createRelinka(options = {}) {
|
|
280
|
-
return new
|
|
377
|
+
return new RelinkaInterface(options);
|
|
281
378
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { LogObject, RelinkaReporter, FormatOptions, RelinkaOptions } from "../../types/mod.js";
|
|
2
2
|
export declare class BasicReporter implements RelinkaReporter {
|
|
3
|
-
formatStack(stack: string
|
|
3
|
+
formatStack(stack: string): string;
|
|
4
4
|
formatArgs(args: any[], opts: FormatOptions): string;
|
|
5
5
|
formatDate(date: Date, opts: FormatOptions): string;
|
|
6
6
|
filterAndJoin(arr: any[]): string;
|
|
@@ -3,17 +3,17 @@ import { parseStack } from "../../utils/error.js";
|
|
|
3
3
|
import { writeStream } from "../../utils/stream.js";
|
|
4
4
|
const bracket = (x) => x ? `[${x}]` : "";
|
|
5
5
|
export class BasicReporter {
|
|
6
|
-
formatStack(stack
|
|
6
|
+
formatStack(stack) {
|
|
7
7
|
return " " + parseStack(stack).join("\n ");
|
|
8
8
|
}
|
|
9
9
|
formatArgs(args, opts) {
|
|
10
|
-
const
|
|
10
|
+
const formattedArgs = args.map((arg) => {
|
|
11
11
|
if (arg && typeof arg.stack === "string") {
|
|
12
|
-
return arg.message + "\n" + this.formatStack(arg.stack
|
|
12
|
+
return arg.message + "\n" + this.formatStack(arg.stack);
|
|
13
13
|
}
|
|
14
14
|
return arg;
|
|
15
15
|
});
|
|
16
|
-
return formatWithOptions(opts, ...
|
|
16
|
+
return formatWithOptions(opts, ...formattedArgs);
|
|
17
17
|
}
|
|
18
18
|
formatDate(date, opts) {
|
|
19
19
|
return opts.date ? date.toLocaleTimeString() : "";
|
|
@@ -26,7 +26,7 @@ export class BasicReporter {
|
|
|
26
26
|
if (logObj.type === "box") {
|
|
27
27
|
return "\n" + [
|
|
28
28
|
bracket(logObj.tag),
|
|
29
|
-
logObj
|
|
29
|
+
logObj["title"] && logObj["title"],
|
|
30
30
|
...message.split("\n")
|
|
31
31
|
].filter(Boolean).map((l) => " > " + l).join("\n") + "\n";
|
|
32
32
|
}
|
|
@@ -8,15 +8,15 @@ export class BrowserReporter {
|
|
|
8
8
|
this.defaultColor = "#7f8c8d";
|
|
9
9
|
this.levelColorMap = {
|
|
10
10
|
0: "#c0392b",
|
|
11
|
-
|
|
11
|
+
// Red
|
|
12
12
|
1: "#f39c12",
|
|
13
|
-
|
|
13
|
+
// Yellow
|
|
14
14
|
3: "#00BCD4"
|
|
15
|
-
|
|
15
|
+
// Cyan
|
|
16
16
|
};
|
|
17
17
|
this.typeColorMap = {
|
|
18
18
|
success: "#2ecc71"
|
|
19
|
-
|
|
19
|
+
// Green
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
22
|
_getLogFn(level) {
|
|
@@ -45,7 +45,7 @@ export class BrowserReporter {
|
|
|
45
45
|
consoleLogFn(
|
|
46
46
|
`${badge}%c ${logObj.args[0]}`,
|
|
47
47
|
style,
|
|
48
|
-
|
|
48
|
+
// Empty string as style resets to default console style
|
|
49
49
|
"",
|
|
50
50
|
...logObj.args.slice(1)
|
|
51
51
|
);
|
|
@@ -5,6 +5,6 @@ export declare const TYPE_COLOR_MAP: Partial<Record<LogType, string>>;
|
|
|
5
5
|
export declare const LEVEL_COLOR_MAP: Partial<Record<LogLevel, string>>;
|
|
6
6
|
export declare class FancyReporter extends BasicReporter {
|
|
7
7
|
formatStack(stack: string): string;
|
|
8
|
-
formatType(logObj: LogObject, isBadge: boolean
|
|
8
|
+
formatType(logObj: LogObject, isBadge: boolean): any;
|
|
9
9
|
formatLogObj(logObj: LogObject, opts: FormatOptions): any;
|
|
10
10
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import isUnicodeSupported from "is-unicode-supported";
|
|
2
|
-
import
|
|
2
|
+
import stringWidth from "string-width";
|
|
3
3
|
import { BasicReporter } from "../../components/reporters/basic.js";
|
|
4
4
|
import { box } from "../../utils/box.js";
|
|
5
5
|
import { colors } from "../../utils/color.js";
|
|
@@ -31,11 +31,11 @@ const TYPE_ICONS = {
|
|
|
31
31
|
start: s("\u25D0", "o"),
|
|
32
32
|
log: ""
|
|
33
33
|
};
|
|
34
|
-
function
|
|
34
|
+
function getStringWidth(str) {
|
|
35
35
|
if (!Intl.Segmenter) {
|
|
36
36
|
return stripAnsi(str).length;
|
|
37
37
|
}
|
|
38
|
-
return
|
|
38
|
+
return stringWidth(str);
|
|
39
39
|
}
|
|
40
40
|
export class FancyReporter extends BasicReporter {
|
|
41
41
|
formatStack(stack) {
|
|
@@ -43,7 +43,7 @@ export class FancyReporter extends BasicReporter {
|
|
|
43
43
|
(line) => " " + line.replace(/^at +/, (m) => colors.gray(m)).replace(/\((.+)\)/, (_, m) => `(${colors.cyan(m)})`)
|
|
44
44
|
).join("\n");
|
|
45
45
|
}
|
|
46
|
-
formatType(logObj, isBadge
|
|
46
|
+
formatType(logObj, isBadge) {
|
|
47
47
|
const typeColor = TYPE_COLOR_MAP[logObj.type] || LEVEL_COLOR_MAP[logObj.level] || "gray";
|
|
48
48
|
if (isBadge) {
|
|
49
49
|
return getBgColor(typeColor)(
|
|
@@ -63,20 +63,20 @@ export class FancyReporter extends BasicReporter {
|
|
|
63
63
|
message + (additional.length > 0 ? "\n" + additional.join("\n") : "")
|
|
64
64
|
),
|
|
65
65
|
{
|
|
66
|
-
title: logObj
|
|
67
|
-
style: logObj
|
|
66
|
+
title: logObj["title"] ? characterFormat(logObj["title"]) : void 0,
|
|
67
|
+
style: logObj["style"]
|
|
68
68
|
}
|
|
69
69
|
);
|
|
70
70
|
}
|
|
71
71
|
const date = this.formatDate(logObj.date, opts);
|
|
72
72
|
const coloredDate = date && colors.gray(date);
|
|
73
|
-
const isBadge = logObj
|
|
74
|
-
const type = this.formatType(logObj, isBadge
|
|
73
|
+
const isBadge = logObj["badge"] ?? logObj.level < 2;
|
|
74
|
+
const type = this.formatType(logObj, isBadge);
|
|
75
75
|
const tag = logObj.tag ? colors.gray(logObj.tag) : "";
|
|
76
76
|
let line;
|
|
77
77
|
const left = this.filterAndJoin([type, characterFormat(message)]);
|
|
78
78
|
const right = this.filterAndJoin(opts.columns ? [tag, coloredDate] : [tag]);
|
|
79
|
-
const space = (opts.columns || 0) -
|
|
79
|
+
const space = (opts.columns || 0) - getStringWidth(left) - getStringWidth(right) - 2;
|
|
80
80
|
line = space > 0 && (opts.columns || 0) >= 80 ? left + " ".repeat(space) + right : (right ? `${colors.gray(`[${right}]`)} ` : "") + left;
|
|
81
81
|
line += characterFormat(
|
|
82
82
|
additional.length > 0 ? "\n" + additional.join("\n") : ""
|
package/dist-npm/main.d.ts
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export * from "./components/
|
|
4
|
-
export declare function createRelinka(options?: Partial<RelinkaOptions & {
|
|
5
|
-
fancy: boolean;
|
|
6
|
-
}>): RelinkaInstance;
|
|
7
|
-
export declare const relinka: RelinkaInstance;
|
|
8
|
-
export default relinka;
|
|
1
|
+
export * from "./components/relinka/mod.js";
|
|
2
|
+
export * from "./components/messages/mod.js";
|
|
3
|
+
export * from "./components/relinka/logger.js";
|
package/dist-npm/main.js
CHANGED
|
@@ -1,34 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { BasicReporter } from "./components/reporters/basic.js";
|
|
5
|
-
import { FancyReporter } from "./components/reporters/fancy.js";
|
|
6
|
-
export * from "./components/modes/shared.js";
|
|
7
|
-
export function createRelinka(options = {}) {
|
|
8
|
-
let level = _getDefaultLogLevel();
|
|
9
|
-
if (process.env.RELINKA_LEVEL) {
|
|
10
|
-
level = Number.parseInt(process.env.RELINKA_LEVEL) ?? level;
|
|
11
|
-
}
|
|
12
|
-
const relinka2 = _createRelinka({
|
|
13
|
-
level,
|
|
14
|
-
defaults: { level },
|
|
15
|
-
stdout: process.stdout,
|
|
16
|
-
stderr: process.stderr,
|
|
17
|
-
reporters: options.reporters || [
|
|
18
|
-
options.fancy ?? !(isCI || isTest) ? new FancyReporter() : new BasicReporter()
|
|
19
|
-
],
|
|
20
|
-
...options
|
|
21
|
-
});
|
|
22
|
-
return relinka2;
|
|
23
|
-
}
|
|
24
|
-
function _getDefaultLogLevel() {
|
|
25
|
-
if (isDebug) {
|
|
26
|
-
return LogLevels.debug;
|
|
27
|
-
}
|
|
28
|
-
if (isTest) {
|
|
29
|
-
return LogLevels.warn;
|
|
30
|
-
}
|
|
31
|
-
return LogLevels.info;
|
|
32
|
-
}
|
|
33
|
-
export const relinka = createRelinka();
|
|
34
|
-
export default relinka;
|
|
1
|
+
export * from "./components/relinka/mod.js";
|
|
2
|
+
export * from "./components/messages/mod.js";
|
|
3
|
+
export * from "./components/relinka/logger.js";
|
package/dist-npm/types/mod.d.ts
CHANGED
|
@@ -1,42 +1,149 @@
|
|
|
1
1
|
import type { LogLevel, LogType } from "../components/levels/levels.js";
|
|
2
2
|
export type RelinkaOptions = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
3
|
+
/**
|
|
4
|
+
* An array of RelinkaReporter instances used to handle and output log messages.
|
|
5
|
+
*/
|
|
6
|
+
reporters: RelinkaReporter[];
|
|
7
|
+
/**
|
|
8
|
+
* A record mapping LogType to InputLogObject, defining the log configuration for each log type.
|
|
9
|
+
* See {@link LogType} and {@link InputLogObject}.
|
|
10
|
+
*/
|
|
11
|
+
types: Record<LogType, InputLogObject>;
|
|
12
|
+
/**
|
|
13
|
+
* The minimum log level to output. See {@link LogLevel}.
|
|
14
|
+
*/
|
|
15
|
+
level: LogLevel;
|
|
16
|
+
/**
|
|
17
|
+
* Default properties applied to all log messages unless overridden. See {@link InputLogObject}.
|
|
18
|
+
*/
|
|
19
|
+
defaults: InputLogObject;
|
|
20
|
+
/**
|
|
21
|
+
* The maximum number of times a log message can be repeated within a given timeframe.
|
|
22
|
+
*/
|
|
23
|
+
throttle: number;
|
|
24
|
+
/**
|
|
25
|
+
* The minimum time in milliseconds that must elapse before a throttled log message can be logged again.
|
|
26
|
+
*/
|
|
27
|
+
throttleMin: number;
|
|
28
|
+
/**
|
|
29
|
+
* The Node.js writable stream for standard output. See {@link NodeJS.WriteStream}.
|
|
30
|
+
* @optional
|
|
31
|
+
*/
|
|
32
|
+
stdout?: NodeJS.WriteStream;
|
|
33
|
+
/**
|
|
34
|
+
* The Node.js writeable stream for standard error output. See {@link NodeJS.WriteStream}.
|
|
35
|
+
* @optional
|
|
36
|
+
*/
|
|
37
|
+
stderr?: NodeJS.WriteStream;
|
|
38
|
+
/**
|
|
39
|
+
* A function that allows you to mock log messages for testing purposes.
|
|
40
|
+
* @optional
|
|
41
|
+
*/
|
|
42
|
+
mockFn?: (type: LogType, defaults: InputLogObject) => (...args: any) => void;
|
|
43
|
+
/**
|
|
44
|
+
* Configuration options for formatting log messages. See {@link FormatOptions}.
|
|
45
|
+
*/
|
|
46
|
+
formatOptions: FormatOptions;
|
|
13
47
|
};
|
|
48
|
+
/**
|
|
49
|
+
* @see https://nodejs.org/api/util.html#util_util_inspect_object_showhidden_depth_colors
|
|
50
|
+
*/
|
|
14
51
|
export type FormatOptions = {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
52
|
+
/**
|
|
53
|
+
* The maximum number of columns to output, affects formatting.
|
|
54
|
+
* @optional
|
|
55
|
+
*/
|
|
56
|
+
columns?: number;
|
|
57
|
+
/**
|
|
58
|
+
* Whether to include timestamp information in log messages.
|
|
59
|
+
* @optional
|
|
60
|
+
*/
|
|
61
|
+
date?: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Whether to use colors in the output.
|
|
64
|
+
* @optional
|
|
65
|
+
*/
|
|
66
|
+
colors?: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Specifies whether or not the output should be compact. Accepts a boolean or numeric level of compactness.
|
|
69
|
+
* @optional
|
|
70
|
+
*/
|
|
71
|
+
compact?: boolean | number;
|
|
72
|
+
/**
|
|
73
|
+
* Allows additional custom formatting options.
|
|
74
|
+
*/
|
|
75
|
+
[key: string]: unknown;
|
|
20
76
|
};
|
|
21
77
|
export type InputLogObject = {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
78
|
+
/**
|
|
79
|
+
* The logging level of the message. See {@link LogLevel}.
|
|
80
|
+
* @optional
|
|
81
|
+
*/
|
|
82
|
+
level?: LogLevel;
|
|
83
|
+
/**
|
|
84
|
+
* A string tag to categorize or identify the log message.
|
|
85
|
+
* @optional
|
|
86
|
+
*/
|
|
87
|
+
tag?: string;
|
|
88
|
+
/**
|
|
89
|
+
* The type of log message, which affects how it's processed and displayed. See {@link LogType}.
|
|
90
|
+
* @optional
|
|
91
|
+
*/
|
|
92
|
+
type?: LogType;
|
|
93
|
+
/**
|
|
94
|
+
* The main log message text.
|
|
95
|
+
* @optional
|
|
96
|
+
*/
|
|
97
|
+
message?: string;
|
|
98
|
+
/**
|
|
99
|
+
* Additional text or texts to be logged with the message.
|
|
100
|
+
* @optional
|
|
101
|
+
*/
|
|
102
|
+
additional?: string | string[];
|
|
103
|
+
/**
|
|
104
|
+
* Additional arguments to be logged with the message.
|
|
105
|
+
* @optional
|
|
106
|
+
*/
|
|
107
|
+
args?: any[];
|
|
108
|
+
/**
|
|
109
|
+
* The date and time when the log message was created.
|
|
110
|
+
* @optional
|
|
111
|
+
*/
|
|
112
|
+
date?: Date;
|
|
29
113
|
};
|
|
30
114
|
export type LogObject = {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
115
|
+
/**
|
|
116
|
+
* The logging level of the message, overridden if required. See {@link LogLevel}.
|
|
117
|
+
*/
|
|
118
|
+
level: LogLevel;
|
|
119
|
+
/**
|
|
120
|
+
* The type of log message, overridden if required. See {@link LogType}.
|
|
121
|
+
*/
|
|
122
|
+
type: LogType;
|
|
123
|
+
/**
|
|
124
|
+
* A string tag to categorize or identify the log message, overridden if necessary.
|
|
125
|
+
*/
|
|
126
|
+
tag: string;
|
|
127
|
+
/**
|
|
128
|
+
* Additional arguments to be logged with the message, overridden if necessary.
|
|
129
|
+
*/
|
|
130
|
+
args: any[];
|
|
131
|
+
/**
|
|
132
|
+
* The date and time the log message was created, overridden if necessary.
|
|
133
|
+
*/
|
|
134
|
+
date: Date;
|
|
135
|
+
/**
|
|
136
|
+
* Allows additional custom properties to be set on the log object.
|
|
137
|
+
*/
|
|
138
|
+
[key: string]: unknown;
|
|
37
139
|
} & InputLogObject;
|
|
38
140
|
export type RelinkaReporter = {
|
|
39
|
-
|
|
141
|
+
/**
|
|
142
|
+
* Defines how a log message is processed and displayed by this reporter.
|
|
143
|
+
* @param logObj The LogObject containing the log information to process. See {@link LogObject}.
|
|
144
|
+
* @param ctx An object containing context information such as options. See {@link RelinkaOptions}.
|
|
145
|
+
*/
|
|
146
|
+
log: (logObj: LogObject, ctx: {
|
|
40
147
|
options: RelinkaOptions;
|
|
41
148
|
}) => void;
|
|
42
149
|
};
|