@reliverse/relinka 1.2.4 → 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 +116 -21
- package/dist-npm/components/relinka/relinka.js +117 -34
- 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 +38 -36
- package/LICENSE.md +0 -21
|
@@ -1,16 +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;
|
|
9
|
-
|
|
7
|
+
// Instance properties for paused state and queue
|
|
10
8
|
_paused;
|
|
11
9
|
_queue;
|
|
12
10
|
_mockFn;
|
|
13
|
-
|
|
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 = {}) {
|
|
14
17
|
const types = options.types || LogTypes;
|
|
15
18
|
this.options = defu(
|
|
16
19
|
{
|
|
@@ -49,18 +52,34 @@ export class Relinka {
|
|
|
49
52
|
this._paused = false;
|
|
50
53
|
this._queue = [];
|
|
51
54
|
}
|
|
52
|
-
|
|
55
|
+
/**
|
|
56
|
+
* Gets the current log level of the Relinka instance.
|
|
57
|
+
*
|
|
58
|
+
* @returns {number} The current log level.
|
|
59
|
+
*/
|
|
60
|
+
get level() {
|
|
53
61
|
return this.options.level;
|
|
54
62
|
}
|
|
55
|
-
|
|
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) {
|
|
56
69
|
this.options.level = _normalizeLogLevel(
|
|
57
70
|
level,
|
|
58
71
|
this.options.types,
|
|
59
72
|
this.options.level
|
|
60
73
|
);
|
|
61
74
|
}
|
|
62
|
-
|
|
63
|
-
|
|
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({
|
|
64
83
|
...this.options,
|
|
65
84
|
...options
|
|
66
85
|
});
|
|
@@ -69,7 +88,13 @@ export class Relinka {
|
|
|
69
88
|
}
|
|
70
89
|
return instance;
|
|
71
90
|
}
|
|
72
|
-
|
|
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) {
|
|
73
98
|
return this.create({
|
|
74
99
|
...this.options,
|
|
75
100
|
defaults: {
|
|
@@ -78,16 +103,36 @@ export class Relinka {
|
|
|
78
103
|
}
|
|
79
104
|
});
|
|
80
105
|
}
|
|
81
|
-
|
|
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) {
|
|
82
113
|
return this.withDefaults({
|
|
83
114
|
tag: this.options.defaults.tag ? this.options.defaults.tag + ":" + tag : tag
|
|
84
115
|
});
|
|
85
116
|
}
|
|
86
|
-
|
|
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) {
|
|
87
125
|
this.options.reporters.push(reporter);
|
|
88
126
|
return this;
|
|
89
127
|
}
|
|
90
|
-
|
|
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) {
|
|
91
136
|
if (reporter) {
|
|
92
137
|
const i = this.options.reporters.indexOf(reporter);
|
|
93
138
|
if (i >= 0) {
|
|
@@ -98,7 +143,13 @@ export class Relinka {
|
|
|
98
143
|
}
|
|
99
144
|
return this;
|
|
100
145
|
}
|
|
101
|
-
|
|
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) {
|
|
102
153
|
this.options.reporters = Array.isArray(reporters) ? reporters : [reporters];
|
|
103
154
|
return this;
|
|
104
155
|
}
|
|
@@ -110,7 +161,10 @@ export class Relinka {
|
|
|
110
161
|
this.restoreConsole();
|
|
111
162
|
this.restoreStd();
|
|
112
163
|
}
|
|
113
|
-
|
|
164
|
+
/**
|
|
165
|
+
* Overrides console methods with Relinka logging methods for consistent logging.
|
|
166
|
+
*/
|
|
167
|
+
wrapConsole() {
|
|
114
168
|
for (const type in this.options.types) {
|
|
115
169
|
if (!console["__" + type]) {
|
|
116
170
|
console["__" + type] = console[type];
|
|
@@ -118,7 +172,10 @@ export class Relinka {
|
|
|
118
172
|
console[type] = this[type].raw;
|
|
119
173
|
}
|
|
120
174
|
}
|
|
121
|
-
|
|
175
|
+
/**
|
|
176
|
+
* Restores the original console methods, removing Relinka overrides.
|
|
177
|
+
*/
|
|
178
|
+
restoreConsole() {
|
|
122
179
|
for (const type in this.options.types) {
|
|
123
180
|
if (console["__" + type]) {
|
|
124
181
|
console[type] = console["__" + type];
|
|
@@ -126,7 +183,10 @@ export class Relinka {
|
|
|
126
183
|
}
|
|
127
184
|
}
|
|
128
185
|
}
|
|
129
|
-
|
|
186
|
+
/**
|
|
187
|
+
* Overrides standard output and error streams to redirect them through RelinkaInterface.
|
|
188
|
+
*/
|
|
189
|
+
wrapStd() {
|
|
130
190
|
this._wrapStream(this.options.stdout, "log");
|
|
131
191
|
this._wrapStream(this.options.stderr, "log");
|
|
132
192
|
}
|
|
@@ -141,7 +201,10 @@ export class Relinka {
|
|
|
141
201
|
this[type].raw(String(data).trim());
|
|
142
202
|
};
|
|
143
203
|
}
|
|
144
|
-
|
|
204
|
+
/**
|
|
205
|
+
* Restores the original standard output and error streams, removing the Relinka redirection.
|
|
206
|
+
*/
|
|
207
|
+
restoreStd() {
|
|
145
208
|
this._restoreStream(this.options.stdout);
|
|
146
209
|
this._restoreStream(this.options.stderr);
|
|
147
210
|
}
|
|
@@ -154,7 +217,14 @@ export class Relinka {
|
|
|
154
217
|
delete stream.__write;
|
|
155
218
|
}
|
|
156
219
|
}
|
|
157
|
-
|
|
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) {
|
|
158
228
|
this._lastLog = {};
|
|
159
229
|
this._queue = [];
|
|
160
230
|
this._paused = false;
|
|
@@ -162,17 +232,28 @@ export class Relinka {
|
|
|
162
232
|
console.clear();
|
|
163
233
|
}
|
|
164
234
|
}
|
|
165
|
-
|
|
235
|
+
/**
|
|
236
|
+
* Pauses logging, queues incoming logs until resumed.
|
|
237
|
+
*/
|
|
238
|
+
pauseLogs() {
|
|
166
239
|
this._paused = true;
|
|
167
240
|
}
|
|
168
|
-
|
|
241
|
+
/**
|
|
242
|
+
* Resumes logging, processing any queued logs.
|
|
243
|
+
*/
|
|
244
|
+
resumeLogs() {
|
|
169
245
|
this._paused = false;
|
|
170
246
|
const _queue = this._queue.splice(0);
|
|
171
247
|
for (const item of _queue) {
|
|
172
248
|
item[0]._logFn(item[1], item[2]);
|
|
173
249
|
}
|
|
174
250
|
}
|
|
175
|
-
|
|
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) {
|
|
176
257
|
const _mockFn = mockFn || this.options.mockFn;
|
|
177
258
|
this._mockFn = _mockFn;
|
|
178
259
|
if (typeof _mockFn !== "function") {
|
|
@@ -183,12 +264,12 @@ export class Relinka {
|
|
|
183
264
|
this[type].raw = this[type];
|
|
184
265
|
}
|
|
185
266
|
}
|
|
186
|
-
|
|
267
|
+
// _wrapLogFn uses instances: _paused, _queue, etc
|
|
187
268
|
_wrapLogFn(defaults, isRaw) {
|
|
188
269
|
return (...args) => {
|
|
189
270
|
if (this._paused) {
|
|
190
271
|
this._queue.push([this, defaults, args, isRaw]);
|
|
191
|
-
return;
|
|
272
|
+
return false;
|
|
192
273
|
}
|
|
193
274
|
return this._logFn(defaults, args, isRaw);
|
|
194
275
|
};
|
|
@@ -198,7 +279,7 @@ export class Relinka {
|
|
|
198
279
|
return false;
|
|
199
280
|
}
|
|
200
281
|
const logObj = {
|
|
201
|
-
date:
|
|
282
|
+
date: /* @__PURE__ */ new Date(),
|
|
202
283
|
args: [],
|
|
203
284
|
...defaults,
|
|
204
285
|
level: _normalizeLogLevel(defaults.level, this.options.types)
|
|
@@ -255,13 +336,15 @@ export class Relinka {
|
|
|
255
336
|
resolveLog,
|
|
256
337
|
this.options.throttle
|
|
257
338
|
);
|
|
258
|
-
return;
|
|
339
|
+
return false;
|
|
259
340
|
}
|
|
260
341
|
}
|
|
261
342
|
} catch {
|
|
343
|
+
return true;
|
|
262
344
|
}
|
|
263
345
|
}
|
|
264
346
|
resolveLog(true);
|
|
347
|
+
return true;
|
|
265
348
|
}
|
|
266
349
|
_log(logObj) {
|
|
267
350
|
for (const reporter of this.options.reporters) {
|
|
@@ -283,13 +366,13 @@ function _normalizeLogLevel(input, types = {}, defaultLevel = 3) {
|
|
|
283
366
|
}
|
|
284
367
|
return defaultLevel;
|
|
285
368
|
}
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
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;
|
|
293
376
|
export function createRelinka(options = {}) {
|
|
294
|
-
return new
|
|
377
|
+
return new RelinkaInterface(options);
|
|
295
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
|
};
|