@reliverse/relinka 1.3.2 → 1.3.4
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/libs/core/core-impl/deprecated/components/core/core.d.ts +1 -0
- package/bin/libs/core/core-impl/deprecated/components/core/core.js +1 -0
- package/bin/libs/core/core-impl/deprecated/components/levels/levels.d.ts +26 -0
- package/{dist-npm → bin/libs/core/core-impl/deprecated}/components/levels/levels.js +15 -15
- package/bin/libs/core/core-impl/deprecated/components/modes/basic.d.ts +20 -0
- package/bin/libs/core/core-impl/deprecated/components/modes/basic.js +21 -0
- package/{dist-npm → bin/libs/core/core-impl/deprecated}/components/modes/browser.d.ts +19 -19
- package/bin/libs/core/core-impl/deprecated/components/modes/browser.js +12 -0
- package/bin/libs/core/core-impl/deprecated/components/modes/shared.d.ts +3 -0
- package/bin/libs/core/core-impl/deprecated/components/modes/shared.js +4 -0
- package/{dist-npm/components/relinka → bin/libs/core/core-impl/deprecated/components/relinka-deprecated}/logger.d.ts +5 -5
- package/bin/libs/core/core-impl/deprecated/components/relinka-deprecated/logger.js +5 -0
- package/{dist-npm/components/relinka → bin/libs/core/core-impl/deprecated/components/relinka-deprecated}/mod.d.ts +21 -21
- package/bin/libs/core/core-impl/deprecated/components/relinka-deprecated/mod.js +34 -0
- package/{dist-npm/components/relinka → bin/libs/core/core-impl/deprecated/components/relinka-deprecated}/relinka.d.ts +141 -140
- package/{dist-npm/components/relinka → bin/libs/core/core-impl/deprecated/components/relinka-deprecated}/relinka.js +30 -27
- package/{dist-npm → bin/libs/core/core-impl/deprecated}/components/reporters/basic.d.ts +11 -11
- package/{dist-npm → bin/libs/core/core-impl/deprecated}/components/reporters/basic.js +10 -6
- package/{dist-npm → bin/libs/core/core-impl/deprecated}/components/reporters/browser.d.ts +10 -10
- package/bin/libs/core/core-impl/deprecated/components/reporters/fancy.d.ts +10 -0
- package/{dist-npm → bin/libs/core/core-impl/deprecated}/components/reporters/fancy.js +19 -12
- package/{dist-npm → bin/libs/core/core-impl/deprecated}/types/mod.d.ts +150 -149
- package/{dist-npm → bin/libs/core/core-impl/deprecated}/utils/box.d.ts +114 -114
- package/{dist-npm → bin/libs/core/core-impl/deprecated}/utils/box.js +1 -1
- package/{dist-npm → bin/libs/core/core-impl/deprecated}/utils/deprecatedColors.d.ts +69 -69
- package/{dist-npm → bin/libs/core/core-impl/deprecated}/utils/deprecatedColors.js +3 -12
- package/{dist-npm → bin/libs/core/core-impl/deprecated}/utils/error.d.ts +6 -6
- package/{dist-npm → bin/libs/core/core-impl/deprecated}/utils/format.d.ts +14 -14
- package/{dist-npm → bin/libs/core/core-impl/deprecated}/utils/format.js +2 -2
- package/{dist-npm → bin/libs/core/core-impl/deprecated}/utils/log.d.ts +13 -13
- package/bin/libs/core/core-impl/deprecated/utils/mod.d.ts +3 -0
- package/bin/libs/core/core-impl/deprecated/utils/mod.js +9 -0
- package/{dist-npm → bin/libs/core/core-impl/deprecated}/utils/stream.d.ts +15 -14
- package/{dist-npm → bin/libs/core/core-impl/deprecated}/utils/string.d.ts +50 -50
- package/{dist-npm → bin/libs/core/core-impl/deprecated}/utils/tree.d.ts +41 -41
- package/bin/libs/core/core-main.d.ts +23 -0
- package/bin/libs/core/core-main.js +49 -0
- package/bin/main.d.ts +1 -0
- package/bin/main.js +1 -0
- package/package.json +47 -83
- package/dist-npm/components/core/core.d.ts +0 -2
- package/dist-npm/components/core/core.js +0 -2
- package/dist-npm/components/levels/levels.d.ts +0 -26
- package/dist-npm/components/modes/basic.d.ts +0 -20
- package/dist-npm/components/modes/basic.js +0 -21
- package/dist-npm/components/modes/browser.js +0 -12
- 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.js +0 -5
- package/dist-npm/components/relinka/mod.js +0 -34
- package/dist-npm/components/reporters/fancy.d.ts +0 -10
- package/dist-npm/main.d.ts +0 -2
- package/dist-npm/main.js +0 -2
- package/dist-npm/utils/mod.d.ts +0 -3
- package/dist-npm/utils/mod.js +0 -9
- /package/{dist-npm → bin/libs/core/core-impl/deprecated}/components/reporters/browser.js +0 -0
- /package/{dist-npm → bin/libs/core/core-impl/deprecated}/types/mod.js +0 -0
- /package/{dist-npm → bin/libs/core/core-impl/deprecated}/utils/error.js +0 -0
- /package/{dist-npm → bin/libs/core/core-impl/deprecated}/utils/log.js +0 -0
- /package/{dist-npm → bin/libs/core/core-impl/deprecated}/utils/stream.js +0 -0
- /package/{dist-npm → bin/libs/core/core-impl/deprecated}/utils/string.js +0 -0
- /package/{dist-npm → bin/libs/core/core-impl/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 { LogTypeDeprecated } from "../levels/levels.js";
|
|
3
|
+
import type { InputLogObject, LogObject, RelinkaOptions, RelinkaReporter } from "../../types/mod.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 {RelinkaInstanceDeprecated} A new Relinka instance. See {@link RelinkaInstanceDeprecated}.
|
|
45
|
+
*/
|
|
46
|
+
create(options: Partial<RelinkaOptions>): RelinkaInstanceDeprecated;
|
|
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 {RelinkaInstanceDeprecated} A new Relinka instance. See {@link RelinkaInstanceDeprecated}.
|
|
52
|
+
*/
|
|
53
|
+
withDefaults(defaults: InputLogObject): RelinkaInstanceDeprecated;
|
|
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 {RelinkaInstanceDeprecated} A new Relinka instance. See {@link RelinkaInstanceDeprecated}.
|
|
59
|
+
*/
|
|
60
|
+
withTag(tag: string): RelinkaInstanceDeprecated;
|
|
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: LogTypeDeprecated): 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 RelinkaInstanceDeprecated = RelinkaInterface & Record<LogTypeDeprecated, 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 {RelinkaInstanceDeprecated} A new instance of RelinkaInterface. See {@link RelinkaInstanceDeprecated}.
|
|
140
|
+
*/
|
|
141
|
+
export declare function createRelinkaDeprecated(options?: Partial<RelinkaOptions>): RelinkaInstanceDeprecated;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defu } from "defu";
|
|
2
|
-
import {
|
|
2
|
+
import { LogTypesDeprecated } from "../modes/shared.js";
|
|
3
3
|
import { isLogObj } from "../../utils/log.js";
|
|
4
4
|
export class RelinkaInterface {
|
|
5
5
|
options;
|
|
@@ -14,16 +14,16 @@ export class RelinkaInterface {
|
|
|
14
14
|
* @param {Partial<RelinkaOptions>} [options={}] - Configuration options for the Relinka instance.
|
|
15
15
|
*/
|
|
16
16
|
constructor(options = {}) {
|
|
17
|
-
const types = options.types ||
|
|
17
|
+
const types = options.types || LogTypesDeprecated;
|
|
18
18
|
this.options = defu(
|
|
19
19
|
{
|
|
20
20
|
...options,
|
|
21
21
|
defaults: { ...options.defaults },
|
|
22
|
-
level:
|
|
22
|
+
level: _normalizeLogLevelDeprecated(options.level, types),
|
|
23
23
|
reporters: [...options.reporters || []]
|
|
24
24
|
},
|
|
25
25
|
{
|
|
26
|
-
types:
|
|
26
|
+
types: LogTypesDeprecated,
|
|
27
27
|
throttle: 1e3,
|
|
28
28
|
throttleMin: 5,
|
|
29
29
|
formatOptions: {
|
|
@@ -40,10 +40,7 @@ export class RelinkaInterface {
|
|
|
40
40
|
...types[type]
|
|
41
41
|
};
|
|
42
42
|
this[type] = this._wrapLogFn(defaults);
|
|
43
|
-
this[type].raw = this._wrapLogFn(
|
|
44
|
-
defaults,
|
|
45
|
-
true
|
|
46
|
-
);
|
|
43
|
+
this[type].raw = this._wrapLogFn(defaults, true);
|
|
47
44
|
}
|
|
48
45
|
if (this.options.mockFn) {
|
|
49
46
|
this.mockTypes();
|
|
@@ -66,7 +63,7 @@ export class RelinkaInterface {
|
|
|
66
63
|
* @param {number} level - The new log level to set.
|
|
67
64
|
*/
|
|
68
65
|
set level(level) {
|
|
69
|
-
this.options.level =
|
|
66
|
+
this.options.level = _normalizeLogLevelDeprecated(
|
|
70
67
|
level,
|
|
71
68
|
this.options.types,
|
|
72
69
|
this.options.level
|
|
@@ -76,7 +73,7 @@ export class RelinkaInterface {
|
|
|
76
73
|
* Creates a new instance of Relinka, inheriting options from the current instance, with possible overrides.
|
|
77
74
|
*
|
|
78
75
|
* @param {Partial<RelinkaOptions>} options - Optional overrides for the new instance. See {@link RelinkaOptions}.
|
|
79
|
-
* @returns {
|
|
76
|
+
* @returns {RelinkaInstanceDeprecated} A new Relinka instance. See {@link RelinkaInstanceDeprecated}.
|
|
80
77
|
*/
|
|
81
78
|
create(options) {
|
|
82
79
|
const instance = new RelinkaInterface({
|
|
@@ -92,7 +89,7 @@ export class RelinkaInterface {
|
|
|
92
89
|
* Creates a new Relinka instance with the specified default log object properties.
|
|
93
90
|
*
|
|
94
91
|
* @param {InputLogObject} defaults - Default properties to include in any log from the new instance. See {@link InputLogObject}.
|
|
95
|
-
* @returns {
|
|
92
|
+
* @returns {RelinkaInstanceDeprecated} A new Relinka instance. See {@link RelinkaInstanceDeprecated}.
|
|
96
93
|
*/
|
|
97
94
|
withDefaults(defaults) {
|
|
98
95
|
return this.create({
|
|
@@ -107,11 +104,11 @@ export class RelinkaInterface {
|
|
|
107
104
|
* Creates a new Relinka instance with a specified tag, which will be included in every log.
|
|
108
105
|
*
|
|
109
106
|
* @param {string} tag - The tag to include in each log of the new instance.
|
|
110
|
-
* @returns {
|
|
107
|
+
* @returns {RelinkaInstanceDeprecated} A new Relinka instance. See {@link RelinkaInstanceDeprecated}.
|
|
111
108
|
*/
|
|
112
109
|
withTag(tag) {
|
|
113
110
|
return this.withDefaults({
|
|
114
|
-
tag: this.options.defaults.tag ? this.options.defaults.tag
|
|
111
|
+
tag: this.options.defaults.tag ? `${this.options.defaults.tag}:${tag}` : tag
|
|
115
112
|
});
|
|
116
113
|
}
|
|
117
114
|
/**
|
|
@@ -166,8 +163,8 @@ export class RelinkaInterface {
|
|
|
166
163
|
*/
|
|
167
164
|
wrapConsole() {
|
|
168
165
|
for (const type in this.options.types) {
|
|
169
|
-
if (!console[
|
|
170
|
-
console[
|
|
166
|
+
if (!console[`__${type}`]) {
|
|
167
|
+
console[`__${type}`] = console[type];
|
|
171
168
|
}
|
|
172
169
|
console[type] = this[type].raw;
|
|
173
170
|
}
|
|
@@ -177,9 +174,9 @@ export class RelinkaInterface {
|
|
|
177
174
|
*/
|
|
178
175
|
restoreConsole() {
|
|
179
176
|
for (const type in this.options.types) {
|
|
180
|
-
if (console[
|
|
181
|
-
console[type] = console[
|
|
182
|
-
delete console[
|
|
177
|
+
if (console[`__${type}`]) {
|
|
178
|
+
console[type] = console[`__${type}`];
|
|
179
|
+
delete console[`__${type}`];
|
|
183
180
|
}
|
|
184
181
|
}
|
|
185
182
|
}
|
|
@@ -198,7 +195,9 @@ export class RelinkaInterface {
|
|
|
198
195
|
stream.__write = stream.write;
|
|
199
196
|
}
|
|
200
197
|
stream.write = (data) => {
|
|
201
|
-
this[type].raw(
|
|
198
|
+
this[type].raw(
|
|
199
|
+
String(data).trim()
|
|
200
|
+
);
|
|
202
201
|
};
|
|
203
202
|
}
|
|
204
203
|
/**
|
|
@@ -214,7 +213,7 @@ export class RelinkaInterface {
|
|
|
214
213
|
}
|
|
215
214
|
if (stream.__write) {
|
|
216
215
|
stream.write = stream.__write;
|
|
217
|
-
|
|
216
|
+
stream.__write = void 0;
|
|
218
217
|
}
|
|
219
218
|
}
|
|
220
219
|
/**
|
|
@@ -260,7 +259,10 @@ export class RelinkaInterface {
|
|
|
260
259
|
return;
|
|
261
260
|
}
|
|
262
261
|
for (const type in this.options.types) {
|
|
263
|
-
this[type] = _mockFn(
|
|
262
|
+
this[type] = _mockFn(
|
|
263
|
+
type,
|
|
264
|
+
this.options.types[type]
|
|
265
|
+
) || this[type];
|
|
264
266
|
this[type].raw = this[type];
|
|
265
267
|
}
|
|
266
268
|
}
|
|
@@ -282,7 +284,7 @@ export class RelinkaInterface {
|
|
|
282
284
|
date: /* @__PURE__ */ new Date(),
|
|
283
285
|
args: [],
|
|
284
286
|
...defaults,
|
|
285
|
-
level:
|
|
287
|
+
level: _normalizeLogLevelDeprecated(defaults.level, this.options.types)
|
|
286
288
|
};
|
|
287
289
|
if (!isRaw && args.length === 1 && isLogObj(args[0])) {
|
|
288
290
|
Object.assign(logObj, args[0]);
|
|
@@ -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 : "";
|
|
@@ -354,7 +357,7 @@ export class RelinkaInterface {
|
|
|
354
357
|
}
|
|
355
358
|
}
|
|
356
359
|
}
|
|
357
|
-
function
|
|
360
|
+
function _normalizeLogLevelDeprecated(input, types = {}, defaultLevel = 3) {
|
|
358
361
|
if (input === void 0) {
|
|
359
362
|
return defaultLevel;
|
|
360
363
|
}
|
|
@@ -373,6 +376,6 @@ RelinkaInterface.prototype.withScope = RelinkaInterface.prototype.withTag;
|
|
|
373
376
|
RelinkaInterface.prototype.mock = RelinkaInterface.prototype.mockTypes;
|
|
374
377
|
RelinkaInterface.prototype.pause = RelinkaInterface.prototype.pauseLogs;
|
|
375
378
|
RelinkaInterface.prototype.resume = RelinkaInterface.prototype.resumeLogs;
|
|
376
|
-
export function
|
|
379
|
+
export function createRelinkaDeprecated(options = {}) {
|
|
377
380
|
return new RelinkaInterface(options);
|
|
378
381
|
}
|
|
@@ -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 "../../types/mod.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
|
+
import type { LogObject } from "../../types/mod.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
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { LogLevelDeprecated, LogTypeDeprecated } from "../levels/levels.js";
|
|
2
|
+
import type { FormatOptions, LogObject } from "../../types/mod.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,7 +1,9 @@
|
|
|
1
1
|
import { isUnicodeSupported } from "@reliverse/runtime";
|
|
2
2
|
import stringWidth from "string-width";
|
|
3
|
-
import { BasicReporter } from "
|
|
4
|
-
import {
|
|
3
|
+
import { BasicReporter } from "./basic.js";
|
|
4
|
+
import {
|
|
5
|
+
box
|
|
6
|
+
} from "../../utils/box.js";
|
|
5
7
|
import { colors } from "../../utils/deprecatedColors.js";
|
|
6
8
|
import { parseStack } from "../../utils/error.js";
|
|
7
9
|
import { stripAnsi } from "../../utils/string.js";
|
|
@@ -39,9 +41,10 @@ function getStringWidth(str) {
|
|
|
39
41
|
}
|
|
40
42
|
export class FancyReporter extends BasicReporter {
|
|
41
43
|
formatStack(stack) {
|
|
42
|
-
return
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
return `
|
|
45
|
+
${parseStack(stack).map(
|
|
46
|
+
(line) => ` ${line.replace(/^at +/, (m) => colors.gray(m)).replace(/\((.+)\)/, (_, m) => `(${colors.cyan(m)})`)}`
|
|
47
|
+
).join("\n")}`;
|
|
45
48
|
}
|
|
46
49
|
formatType(logObj, isBadge) {
|
|
47
50
|
const typeColor = TYPE_COLOR_MAP[logObj.type] || LEVEL_COLOR_MAP[logObj.level] || "gray";
|
|
@@ -60,17 +63,18 @@ export class FancyReporter extends BasicReporter {
|
|
|
60
63
|
if (logObj.type === "box") {
|
|
61
64
|
return box(
|
|
62
65
|
characterFormat(
|
|
63
|
-
message + (additional.length > 0 ?
|
|
66
|
+
message + (additional.length > 0 ? `
|
|
67
|
+
${additional.join("\n")}` : "")
|
|
64
68
|
),
|
|
65
69
|
{
|
|
66
|
-
title: logObj
|
|
67
|
-
style: logObj
|
|
70
|
+
title: logObj.title ? characterFormat(logObj.title) : void 0,
|
|
71
|
+
style: logObj.style
|
|
68
72
|
}
|
|
69
73
|
);
|
|
70
74
|
}
|
|
71
75
|
const date = this.formatDate(logObj.date, opts);
|
|
72
76
|
const coloredDate = date && colors.gray(date);
|
|
73
|
-
const isBadge = logObj
|
|
77
|
+
const isBadge = logObj.badge ?? logObj.level < 2;
|
|
74
78
|
const type = this.formatType(logObj, isBadge);
|
|
75
79
|
const tag = logObj.tag ? colors.gray(logObj.tag) : "";
|
|
76
80
|
let line;
|
|
@@ -79,13 +83,16 @@ export class FancyReporter extends BasicReporter {
|
|
|
79
83
|
const space = (opts.columns || 0) - getStringWidth(left) - getStringWidth(right) - 2;
|
|
80
84
|
line = space > 0 && (opts.columns || 0) >= 80 ? left + " ".repeat(space) + right : (right ? `${colors.gray(`[${right}]`)} ` : "") + left;
|
|
81
85
|
line += characterFormat(
|
|
82
|
-
additional.length > 0 ?
|
|
86
|
+
additional.length > 0 ? `
|
|
87
|
+
${additional.join("\n")}` : ""
|
|
83
88
|
);
|
|
84
89
|
if (logObj.type === "trace") {
|
|
85
|
-
const _err = new Error(
|
|
90
|
+
const _err = new Error(`Trace: ${logObj.message}`);
|
|
86
91
|
line += this.formatStack(_err.stack || "");
|
|
87
92
|
}
|
|
88
|
-
return isBadge ?
|
|
93
|
+
return isBadge ? `
|
|
94
|
+
${line}
|
|
95
|
+
` : line;
|
|
89
96
|
}
|
|
90
97
|
}
|
|
91
98
|
function characterFormat(str) {
|