@reliverse/relinka 1.3.1 → 1.3.3
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 +1 -1
- package/README.md +87 -134
- package/bin/deprecated/components/core/core.d.ts +2 -0
- package/bin/deprecated/components/core/core.js +2 -0
- package/{dist-npm → bin/deprecated}/components/levels/levels.d.ts +26 -26
- package/{dist-npm → bin/deprecated}/components/modes/basic.d.ts +20 -20
- package/{dist-npm → bin/deprecated}/components/modes/basic.js +5 -5
- package/{dist-npm → bin/deprecated}/components/modes/browser.d.ts +19 -19
- package/{dist-npm → bin/deprecated}/components/modes/browser.js +2 -2
- package/bin/deprecated/components/modes/shared.d.ts +5 -0
- package/bin/deprecated/components/modes/shared.js +2 -0
- package/bin/deprecated/components/relinka/logger.d.ts +5 -0
- package/bin/deprecated/components/relinka/logger.js +5 -0
- package/{dist-npm → bin/deprecated}/components/relinka/mod.d.ts +21 -21
- package/{dist-npm → bin/deprecated}/components/relinka/mod.js +3 -3
- package/{dist-npm → bin/deprecated}/components/relinka/relinka.d.ts +141 -140
- package/{dist-npm → bin/deprecated}/components/relinka/relinka.js +14 -11
- package/{dist-npm → bin/deprecated}/components/reporters/basic.d.ts +11 -11
- package/{dist-npm → bin/deprecated}/components/reporters/basic.js +10 -6
- package/{dist-npm → bin/deprecated}/components/reporters/browser.d.ts +10 -10
- package/{dist-npm → bin/deprecated}/components/reporters/fancy.d.ts +10 -10
- package/{dist-npm → bin/deprecated}/components/reporters/fancy.js +16 -11
- package/{dist-npm/main.d.ts → bin/deprecated/depd-main.d.ts} +2 -3
- package/{dist-npm/main.js → bin/deprecated/depd-main.js} +0 -1
- package/{dist-npm → bin/deprecated}/types/mod.d.ts +150 -149
- package/{dist-npm → bin/deprecated}/utils/box.d.ts +114 -114
- package/{dist-npm → bin/deprecated}/utils/box.js +1 -1
- package/{dist-npm → bin/deprecated}/utils/deprecatedColors.d.ts +69 -69
- package/{dist-npm → bin/deprecated}/utils/deprecatedColors.js +3 -9
- package/{dist-npm → bin/deprecated}/utils/error.d.ts +6 -6
- package/{dist-npm → bin/deprecated}/utils/format.d.ts +14 -14
- package/{dist-npm → bin/deprecated}/utils/format.js +2 -2
- package/{dist-npm → bin/deprecated}/utils/log.d.ts +13 -13
- package/bin/deprecated/utils/mod.d.ts +3 -0
- package/bin/deprecated/utils/mod.js +9 -0
- package/{dist-npm → bin/deprecated}/utils/stream.d.ts +15 -14
- package/{dist-npm → bin/deprecated}/utils/string.d.ts +50 -50
- package/{dist-npm → bin/deprecated}/utils/tree.d.ts +41 -41
- package/bin/main.d.ts +1 -0
- package/bin/main.js +1 -0
- package/package.json +46 -83
- package/dist-npm/components/core/core.d.ts +0 -2
- package/dist-npm/components/core/core.js +0 -2
- package/dist-npm/components/messages/mapping.d.ts +0 -3
- package/dist-npm/components/messages/mapping.js +0 -49
- package/dist-npm/components/messages/messages.d.ts +0 -89
- package/dist-npm/components/messages/messages.js +0 -314
- package/dist-npm/components/messages/mod.d.ts +0 -5
- package/dist-npm/components/messages/mod.js +0 -5
- package/dist-npm/components/messages/terminal.d.ts +0 -15
- package/dist-npm/components/messages/terminal.js +0 -57
- package/dist-npm/components/messages/types.d.ts +0 -12
- package/dist-npm/components/messages/types.js +0 -0
- package/dist-npm/components/messages/variants.d.ts +0 -12
- package/dist-npm/components/messages/variants.js +0 -52
- package/dist-npm/components/modes/shared.d.ts +0 -5
- package/dist-npm/components/modes/shared.js +0 -2
- package/dist-npm/components/relinka/logger.d.ts +0 -12
- package/dist-npm/components/relinka/logger.js +0 -52
- package/dist-npm/utils/mod.d.ts +0 -3
- package/dist-npm/utils/mod.js +0 -9
- /package/{dist-npm → bin/deprecated}/components/levels/levels.js +0 -0
- /package/{dist-npm → bin/deprecated}/components/reporters/browser.js +0 -0
- /package/{dist-npm → bin/deprecated}/types/mod.js +0 -0
- /package/{dist-npm → bin/deprecated}/utils/error.js +0 -0
- /package/{dist-npm → bin/deprecated}/utils/log.js +0 -0
- /package/{dist-npm → bin/deprecated}/utils/stream.js +0 -0
- /package/{dist-npm → bin/deprecated}/utils/string.js +0 -0
- /package/{dist-npm → bin/deprecated}/utils/tree.js +0 -0
|
@@ -1,140 +1,141 @@
|
|
|
1
|
-
|
|
2
|
-
import type {
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
* @
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
* @
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
* @
|
|
139
|
-
|
|
140
|
-
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { InputLogObject, LogObject, RelinkaOptions, RelinkaReporter } from "../../types/mod.js";
|
|
3
|
+
import { type LogType } from "../levels/levels.js";
|
|
4
|
+
/**
|
|
5
|
+
* Relinka class for logging management with support for pause/resume, mocking and customizable reporting.
|
|
6
|
+
* Provides flexible logging capabilities including level-based logging, custom reporters and integration options.
|
|
7
|
+
*
|
|
8
|
+
* @class Relinka
|
|
9
|
+
*/
|
|
10
|
+
export declare class RelinkaInterface {
|
|
11
|
+
options: RelinkaOptions;
|
|
12
|
+
_lastLog: {
|
|
13
|
+
serialized?: string;
|
|
14
|
+
object?: LogObject;
|
|
15
|
+
count?: number;
|
|
16
|
+
time?: Date;
|
|
17
|
+
timeout?: ReturnType<typeof setTimeout>;
|
|
18
|
+
};
|
|
19
|
+
_paused: boolean;
|
|
20
|
+
_queue: any[];
|
|
21
|
+
_mockFn?: RelinkaOptions["mockFn"];
|
|
22
|
+
/**
|
|
23
|
+
* Creates an instance of Relinka with specified options or defaults.
|
|
24
|
+
*
|
|
25
|
+
* @param {Partial<RelinkaOptions>} [options={}] - Configuration options for the Relinka instance.
|
|
26
|
+
*/
|
|
27
|
+
constructor(options?: Partial<RelinkaOptions>);
|
|
28
|
+
/**
|
|
29
|
+
* Gets the current log level of the Relinka instance.
|
|
30
|
+
*
|
|
31
|
+
* @returns {number} The current log level.
|
|
32
|
+
*/
|
|
33
|
+
get level(): any;
|
|
34
|
+
/**
|
|
35
|
+
* Sets the minimum log level that will be output by the instance.
|
|
36
|
+
*
|
|
37
|
+
* @param {number} level - The new log level to set.
|
|
38
|
+
*/
|
|
39
|
+
set level(level: any);
|
|
40
|
+
/**
|
|
41
|
+
* Creates a new instance of Relinka, inheriting options from the current instance, with possible overrides.
|
|
42
|
+
*
|
|
43
|
+
* @param {Partial<RelinkaOptions>} options - Optional overrides for the new instance. See {@link RelinkaOptions}.
|
|
44
|
+
* @returns {RelinkaInstance} A new Relinka instance. See {@link RelinkaInstance}.
|
|
45
|
+
*/
|
|
46
|
+
create(options: Partial<RelinkaOptions>): RelinkaInstance;
|
|
47
|
+
/**
|
|
48
|
+
* Creates a new Relinka instance with the specified default log object properties.
|
|
49
|
+
*
|
|
50
|
+
* @param {InputLogObject} defaults - Default properties to include in any log from the new instance. See {@link InputLogObject}.
|
|
51
|
+
* @returns {RelinkaInstance} A new Relinka instance. See {@link RelinkaInstance}.
|
|
52
|
+
*/
|
|
53
|
+
withDefaults(defaults: InputLogObject): RelinkaInstance;
|
|
54
|
+
/**
|
|
55
|
+
* Creates a new Relinka instance with a specified tag, which will be included in every log.
|
|
56
|
+
*
|
|
57
|
+
* @param {string} tag - The tag to include in each log of the new instance.
|
|
58
|
+
* @returns {RelinkaInstance} A new Relinka instance. See {@link RelinkaInstance}.
|
|
59
|
+
*/
|
|
60
|
+
withTag(tag: string): RelinkaInstance;
|
|
61
|
+
/**
|
|
62
|
+
* Adds a custom reporter to the Relinka instance.
|
|
63
|
+
* Reporters will be called for each log message, depending on their implementation and log level.
|
|
64
|
+
*
|
|
65
|
+
* @param {RelinkaReporter} reporter - The reporter to add. See {@link RelinkaReporter}.
|
|
66
|
+
* @returns {Relinka} The current Relinka instance.
|
|
67
|
+
*/
|
|
68
|
+
addReporter(reporter: RelinkaReporter): this;
|
|
69
|
+
/**
|
|
70
|
+
* Removes a custom reporter from the Relinka instance.
|
|
71
|
+
* If no reporter is specified, all reporters will be removed.
|
|
72
|
+
*
|
|
73
|
+
* @param {RelinkaReporter} reporter - The reporter to remove. See {@link RelinkaReporter}.
|
|
74
|
+
* @returns {Relinka} The current Relinka instance.
|
|
75
|
+
*/
|
|
76
|
+
removeReporter(reporter: RelinkaReporter): any;
|
|
77
|
+
/**
|
|
78
|
+
* Replaces all reporters of the Relinka instance with the specified array of reporters.
|
|
79
|
+
*
|
|
80
|
+
* @param {RelinkaReporter[]} reporters - The new reporters to set. See {@link RelinkaReporter}.
|
|
81
|
+
* @returns {Relinka} The current Relinka instance.
|
|
82
|
+
*/
|
|
83
|
+
setReporters(reporters: RelinkaReporter[]): this;
|
|
84
|
+
wrapAll(): void;
|
|
85
|
+
restoreAll(): void;
|
|
86
|
+
/**
|
|
87
|
+
* Overrides console methods with Relinka logging methods for consistent logging.
|
|
88
|
+
*/
|
|
89
|
+
wrapConsole(): void;
|
|
90
|
+
/**
|
|
91
|
+
* Restores the original console methods, removing Relinka overrides.
|
|
92
|
+
*/
|
|
93
|
+
restoreConsole(): void;
|
|
94
|
+
/**
|
|
95
|
+
* Overrides standard output and error streams to redirect them through RelinkaInterface.
|
|
96
|
+
*/
|
|
97
|
+
wrapStd(): void;
|
|
98
|
+
_wrapStream(stream: NodeJS.WriteStream | undefined, type: LogType): void;
|
|
99
|
+
/**
|
|
100
|
+
* Restores the original standard output and error streams, removing the Relinka redirection.
|
|
101
|
+
*/
|
|
102
|
+
restoreStd(): void;
|
|
103
|
+
_restoreStream(stream?: NodeJS.WriteStream): void;
|
|
104
|
+
/**
|
|
105
|
+
* Clears the internal state of the Relinka instance.
|
|
106
|
+
* This will reset any throttling, last log data, clear any queued logs,
|
|
107
|
+
* and optionally clear the actual console.
|
|
108
|
+
*
|
|
109
|
+
* @param {boolean} clearConsole - Whether to clear the actual console. Defaults to false.
|
|
110
|
+
*/
|
|
111
|
+
clear(clearConsole?: boolean): void;
|
|
112
|
+
/**
|
|
113
|
+
* Pauses logging, queues incoming logs until resumed.
|
|
114
|
+
*/
|
|
115
|
+
pauseLogs(): void;
|
|
116
|
+
/**
|
|
117
|
+
* Resumes logging, processing any queued logs.
|
|
118
|
+
*/
|
|
119
|
+
resumeLogs(): void;
|
|
120
|
+
/**
|
|
121
|
+
* Replaces logging methods with mocks if a mock function is provided.
|
|
122
|
+
*
|
|
123
|
+
* @param {RelinkaOptions["mockFn"]} mockFn - The function to use for mocking logging methods. See {@link RelinkaOptions["mockFn"]}.
|
|
124
|
+
*/
|
|
125
|
+
mockTypes(mockFn?: RelinkaOptions["mockFn"]): void;
|
|
126
|
+
_wrapLogFn(defaults: InputLogObject, isRaw?: boolean): (...args: any[]) => boolean;
|
|
127
|
+
_logFn(defaults: InputLogObject, args: any[], isRaw?: boolean): boolean;
|
|
128
|
+
_log(logObj: LogObject): void;
|
|
129
|
+
}
|
|
130
|
+
export type LogFn = {
|
|
131
|
+
(message: InputLogObject | any, ...args: any[]): void;
|
|
132
|
+
raw: (...args: any[]) => void;
|
|
133
|
+
};
|
|
134
|
+
export type RelinkaInstance = RelinkaInterface & Record<LogType, LogFn>;
|
|
135
|
+
/**
|
|
136
|
+
* Utility for creating a new Relinka instance with optional configuration.
|
|
137
|
+
*
|
|
138
|
+
* @param {Partial<RelinkaOptions>} [options={}] - Optional configuration options for the new Relinka instance. See {@link RelinkaOptions}.
|
|
139
|
+
* @returns {RelinkaInstance} A new instance of RelinkaInterface. See {@link RelinkaInstance}.
|
|
140
|
+
*/
|
|
141
|
+
export declare function createRelinka(options?: Partial<RelinkaOptions>): RelinkaInstance;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { defu } from "defu";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
LogTypes
|
|
4
|
+
} from "../levels/levels.js";
|
|
3
5
|
import { isLogObj } from "../../utils/log.js";
|
|
4
6
|
export class RelinkaInterface {
|
|
5
7
|
options;
|
|
@@ -111,7 +113,7 @@ export class RelinkaInterface {
|
|
|
111
113
|
*/
|
|
112
114
|
withTag(tag) {
|
|
113
115
|
return this.withDefaults({
|
|
114
|
-
tag: this.options.defaults.tag ? this.options.defaults.tag
|
|
116
|
+
tag: this.options.defaults.tag ? `${this.options.defaults.tag}:${tag}` : tag
|
|
115
117
|
});
|
|
116
118
|
}
|
|
117
119
|
/**
|
|
@@ -166,8 +168,8 @@ export class RelinkaInterface {
|
|
|
166
168
|
*/
|
|
167
169
|
wrapConsole() {
|
|
168
170
|
for (const type in this.options.types) {
|
|
169
|
-
if (!console[
|
|
170
|
-
console[
|
|
171
|
+
if (!console[`__${type}`]) {
|
|
172
|
+
console[`__${type}`] = console[type];
|
|
171
173
|
}
|
|
172
174
|
console[type] = this[type].raw;
|
|
173
175
|
}
|
|
@@ -177,9 +179,9 @@ export class RelinkaInterface {
|
|
|
177
179
|
*/
|
|
178
180
|
restoreConsole() {
|
|
179
181
|
for (const type in this.options.types) {
|
|
180
|
-
if (console[
|
|
181
|
-
console[type] = console[
|
|
182
|
-
delete console[
|
|
182
|
+
if (console[`__${type}`]) {
|
|
183
|
+
console[type] = console[`__${type}`];
|
|
184
|
+
delete console[`__${type}`];
|
|
183
185
|
}
|
|
184
186
|
}
|
|
185
187
|
}
|
|
@@ -214,7 +216,7 @@ export class RelinkaInterface {
|
|
|
214
216
|
}
|
|
215
217
|
if (stream.__write) {
|
|
216
218
|
stream.write = stream.__write;
|
|
217
|
-
|
|
219
|
+
stream.__write = void 0;
|
|
218
220
|
}
|
|
219
221
|
}
|
|
220
222
|
/**
|
|
@@ -291,14 +293,15 @@ export class RelinkaInterface {
|
|
|
291
293
|
}
|
|
292
294
|
if (logObj.message) {
|
|
293
295
|
logObj.args.unshift(logObj.message);
|
|
294
|
-
|
|
296
|
+
logObj.message = void 0;
|
|
295
297
|
}
|
|
296
298
|
if (logObj.additional) {
|
|
297
299
|
if (!Array.isArray(logObj.additional)) {
|
|
298
300
|
logObj.additional = logObj.additional.split("\n");
|
|
299
301
|
}
|
|
300
|
-
logObj.args.push(
|
|
301
|
-
|
|
302
|
+
logObj.args.push(`
|
|
303
|
+
${logObj.additional.join("\n")}`);
|
|
304
|
+
logObj.additional = void 0;
|
|
302
305
|
}
|
|
303
306
|
logObj.type = typeof logObj.type === "string" ? logObj.type.toLowerCase() : "log";
|
|
304
307
|
logObj.tag = typeof logObj.tag === "string" ? logObj.tag : "";
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { LogObject, RelinkaReporter, FormatOptions, RelinkaOptions } from "../../types/mod.js";
|
|
2
|
-
export declare class BasicReporter implements RelinkaReporter {
|
|
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: RelinkaOptions;
|
|
10
|
-
}): any;
|
|
11
|
-
}
|
|
1
|
+
import type { LogObject, RelinkaReporter, FormatOptions, RelinkaOptions } from "../../types/mod.js";
|
|
2
|
+
export declare class BasicReporter implements RelinkaReporter {
|
|
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: RelinkaOptions;
|
|
10
|
+
}): any;
|
|
11
|
+
}
|
|
@@ -4,12 +4,13 @@ import { writeStream } from "../../utils/stream.js";
|
|
|
4
4
|
const bracket = (x) => x ? `[${x}]` : "";
|
|
5
5
|
export class BasicReporter {
|
|
6
6
|
formatStack(stack) {
|
|
7
|
-
return
|
|
7
|
+
return ` ${parseStack(stack).join("\n ")}`;
|
|
8
8
|
}
|
|
9
9
|
formatArgs(args, opts) {
|
|
10
10
|
const formattedArgs = args.map((arg) => {
|
|
11
11
|
if (arg && typeof arg.stack === "string") {
|
|
12
|
-
return arg.message
|
|
12
|
+
return `${arg.message}
|
|
13
|
+
${this.formatStack(arg.stack)}`;
|
|
13
14
|
}
|
|
14
15
|
return arg;
|
|
15
16
|
});
|
|
@@ -24,11 +25,13 @@ export class BasicReporter {
|
|
|
24
25
|
formatLogObj(logObj, opts) {
|
|
25
26
|
const message = this.formatArgs(logObj.args, opts);
|
|
26
27
|
if (logObj.type === "box") {
|
|
27
|
-
return
|
|
28
|
+
return `
|
|
29
|
+
${[
|
|
28
30
|
bracket(logObj.tag),
|
|
29
|
-
logObj
|
|
31
|
+
logObj.title && logObj.title,
|
|
30
32
|
...message.split("\n")
|
|
31
|
-
].filter(Boolean).map((l) =>
|
|
33
|
+
].filter(Boolean).map((l) => ` > ${l}`).join("\n")}
|
|
34
|
+
`;
|
|
32
35
|
}
|
|
33
36
|
return this.filterAndJoin([
|
|
34
37
|
bracket(logObj.type),
|
|
@@ -42,7 +45,8 @@ export class BasicReporter {
|
|
|
42
45
|
...ctx.options.formatOptions
|
|
43
46
|
});
|
|
44
47
|
return writeStream(
|
|
45
|
-
line
|
|
48
|
+
`${line}
|
|
49
|
+
`,
|
|
46
50
|
logObj.level < 2 ? ctx.options.stderr || process.stderr : ctx.options.stdout || process.stdout
|
|
47
51
|
);
|
|
48
52
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { LogObject } from "
|
|
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
|
+
import type { LogObject } from "../../../main.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,10 +1,10 @@
|
|
|
1
|
-
import type { LogLevel, LogType } from "
|
|
2
|
-
import type { FormatOptions, LogObject } from "
|
|
3
|
-
import { BasicReporter } from "
|
|
4
|
-
export declare const TYPE_COLOR_MAP: Partial<Record<LogType, string>>;
|
|
5
|
-
export declare const LEVEL_COLOR_MAP: Partial<Record<LogLevel, 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
|
+
import type { LogLevel, LogType } from "../levels/levels.js";
|
|
2
|
+
import type { FormatOptions, LogObject } from "../../../main.js";
|
|
3
|
+
import { BasicReporter } from "./basic.js";
|
|
4
|
+
export declare const TYPE_COLOR_MAP: Partial<Record<LogType, string>>;
|
|
5
|
+
export declare const LEVEL_COLOR_MAP: Partial<Record<LogLevel, 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,6 +1,6 @@
|
|
|
1
1
|
import { isUnicodeSupported } from "@reliverse/runtime";
|
|
2
2
|
import stringWidth from "string-width";
|
|
3
|
-
import { BasicReporter } from "
|
|
3
|
+
import { BasicReporter } from "./basic.js";
|
|
4
4
|
import { box } from "../../utils/box.js";
|
|
5
5
|
import { colors } from "../../utils/deprecatedColors.js";
|
|
6
6
|
import { parseStack } from "../../utils/error.js";
|
|
@@ -39,9 +39,10 @@ function getStringWidth(str) {
|
|
|
39
39
|
}
|
|
40
40
|
export class FancyReporter extends BasicReporter {
|
|
41
41
|
formatStack(stack) {
|
|
42
|
-
return
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
return `
|
|
43
|
+
${parseStack(stack).map(
|
|
44
|
+
(line) => ` ${line.replace(/^at +/, (m) => colors.gray(m)).replace(/\((.+)\)/, (_, m) => `(${colors.cyan(m)})`)}`
|
|
45
|
+
).join("\n")}`;
|
|
45
46
|
}
|
|
46
47
|
formatType(logObj, isBadge) {
|
|
47
48
|
const typeColor = TYPE_COLOR_MAP[logObj.type] || LEVEL_COLOR_MAP[logObj.level] || "gray";
|
|
@@ -60,17 +61,18 @@ export class FancyReporter extends BasicReporter {
|
|
|
60
61
|
if (logObj.type === "box") {
|
|
61
62
|
return box(
|
|
62
63
|
characterFormat(
|
|
63
|
-
message + (additional.length > 0 ?
|
|
64
|
+
message + (additional.length > 0 ? `
|
|
65
|
+
${additional.join("\n")}` : "")
|
|
64
66
|
),
|
|
65
67
|
{
|
|
66
|
-
title: logObj
|
|
67
|
-
style: logObj
|
|
68
|
+
title: logObj.title ? characterFormat(logObj.title) : void 0,
|
|
69
|
+
style: logObj.style
|
|
68
70
|
}
|
|
69
71
|
);
|
|
70
72
|
}
|
|
71
73
|
const date = this.formatDate(logObj.date, opts);
|
|
72
74
|
const coloredDate = date && colors.gray(date);
|
|
73
|
-
const isBadge = logObj
|
|
75
|
+
const isBadge = logObj.badge ?? logObj.level < 2;
|
|
74
76
|
const type = this.formatType(logObj, isBadge);
|
|
75
77
|
const tag = logObj.tag ? colors.gray(logObj.tag) : "";
|
|
76
78
|
let line;
|
|
@@ -79,13 +81,16 @@ export class FancyReporter extends BasicReporter {
|
|
|
79
81
|
const space = (opts.columns || 0) - getStringWidth(left) - getStringWidth(right) - 2;
|
|
80
82
|
line = space > 0 && (opts.columns || 0) >= 80 ? left + " ".repeat(space) + right : (right ? `${colors.gray(`[${right}]`)} ` : "") + left;
|
|
81
83
|
line += characterFormat(
|
|
82
|
-
additional.length > 0 ?
|
|
84
|
+
additional.length > 0 ? `
|
|
85
|
+
${additional.join("\n")}` : ""
|
|
83
86
|
);
|
|
84
87
|
if (logObj.type === "trace") {
|
|
85
|
-
const _err = new Error(
|
|
88
|
+
const _err = new Error(`Trace: ${logObj.message}`);
|
|
86
89
|
line += this.formatStack(_err.stack || "");
|
|
87
90
|
}
|
|
88
|
-
return isBadge ?
|
|
91
|
+
return isBadge ? `
|
|
92
|
+
${line}
|
|
93
|
+
` : line;
|
|
89
94
|
}
|
|
90
95
|
}
|
|
91
96
|
function characterFormat(str) {
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
export * from "./components/relinka/mod.js";
|
|
2
|
-
export * from "./components/
|
|
3
|
-
export * from "./components/relinka/logger.js";
|
|
1
|
+
export * from "./components/relinka/mod.js";
|
|
2
|
+
export * from "./components/relinka/logger.js";
|