@workleap/logrocket 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/CHANGELOG.md +18 -0
- package/dist/LogRocketLogger.d.ts +12 -12
- package/dist/LogRocketLogger.js +88 -57
- package/dist/LogRocketLogger.js.map +1 -1
- package/package.json +3 -3
- package/src/LogRocketLogger.ts +109 -60
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @workleap/logrocket
|
|
2
2
|
|
|
3
|
+
## 1.2.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#68](https://github.com/workleap/wl-telemetry/pull/68) [`80c1f39`](https://github.com/workleap/wl-telemetry/commit/80c1f39747ac689d6e175ff6b880a2b8c8fa9abd) Thanks [@patricklafrance](https://github.com/patricklafrance)! - LogRocketLogger refactor.
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`80c1f39`](https://github.com/workleap/wl-telemetry/commit/80c1f39747ac689d6e175ff6b880a2b8c8fa9abd)]:
|
|
10
|
+
- @workleap/telemetry@1.1.6
|
|
11
|
+
|
|
12
|
+
## 1.2.4
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- [#66](https://github.com/workleap/wl-telemetry/pull/66) [`6b79793`](https://github.com/workleap/wl-telemetry/commit/6b79793e26937f562f51193aedec1a7f57b1578c) Thanks [@patricklafrance](https://github.com/patricklafrance)! - Bumped dependencies and LogRocketLogger refactor.
|
|
17
|
+
|
|
18
|
+
- Updated dependencies [[`6b79793`](https://github.com/workleap/wl-telemetry/commit/6b79793e26937f562f51193aedec1a7f57b1578c)]:
|
|
19
|
+
- @workleap/telemetry@1.1.5
|
|
20
|
+
|
|
3
21
|
## 1.2.3
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
|
@@ -12,7 +12,7 @@ export declare class LogRocketLoggerScope implements LoggerScope {
|
|
|
12
12
|
/**
|
|
13
13
|
* @see {@link https://workleap.github.io/wl-logging}
|
|
14
14
|
*/
|
|
15
|
-
withText(text?: string, options?: LogOptions): this;
|
|
15
|
+
withText(text?: string, options?: Omit<LogOptions, "style">): this;
|
|
16
16
|
/**
|
|
17
17
|
* @see {@link https://workleap.github.io/wl-logging}
|
|
18
18
|
*/
|
|
@@ -29,27 +29,27 @@ export declare class LogRocketLoggerScope implements LoggerScope {
|
|
|
29
29
|
* Write a debug log. The log will be processed only if the logger LogLevel is >= debug.
|
|
30
30
|
* @see {@link https://workleap.github.io/wl-logging}
|
|
31
31
|
*/
|
|
32
|
-
debug(log?: string
|
|
32
|
+
debug(log?: string): void;
|
|
33
33
|
/**
|
|
34
34
|
* Write an information log. The log will be processed only if the logger LogLevel is >= information.
|
|
35
35
|
* @see {@link https://workleap.github.io/wl-logging}
|
|
36
36
|
*/
|
|
37
|
-
information(log?: string
|
|
37
|
+
information(log?: string): void;
|
|
38
38
|
/**
|
|
39
39
|
* Write a warning log. The log will be processed only if the logger LogLevel is >= warning.
|
|
40
40
|
* @see {@link https://workleap.github.io/wl-logging}
|
|
41
41
|
*/
|
|
42
|
-
warning(log?: string
|
|
42
|
+
warning(log?: string): void;
|
|
43
43
|
/**
|
|
44
44
|
* Write an error log. The log will be processed only if the logger LogLevel is >= error.
|
|
45
45
|
* @see {@link https://workleap.github.io/wl-logging}
|
|
46
46
|
*/
|
|
47
|
-
error(log?: string
|
|
47
|
+
error(log?: string): void;
|
|
48
48
|
/**
|
|
49
49
|
* Write a critical log. The log will be processed only if the logger LogLevel is >= critical.
|
|
50
50
|
* @see {@link https://workleap.github.io/wl-logging}
|
|
51
51
|
*/
|
|
52
|
-
critical(log?: string
|
|
52
|
+
critical(log?: string): void;
|
|
53
53
|
/**
|
|
54
54
|
* @see {@link https://workleap.github.io/wl-logging}
|
|
55
55
|
*/
|
|
@@ -72,7 +72,7 @@ export declare class LogRocketLogger implements Logger {
|
|
|
72
72
|
/**
|
|
73
73
|
* @see {@link https://workleap.github.io/wl-logging}
|
|
74
74
|
*/
|
|
75
|
-
withText(text?: string, options?: LogOptions): this;
|
|
75
|
+
withText(text?: string, options?: Omit<LogOptions, "style">): this;
|
|
76
76
|
/**
|
|
77
77
|
* @see {@link https://workleap.github.io/wl-logging}
|
|
78
78
|
*/
|
|
@@ -89,27 +89,27 @@ export declare class LogRocketLogger implements Logger {
|
|
|
89
89
|
* Write a debug log. The log will be processed only if the logger LogLevel is >= debug.
|
|
90
90
|
* @see {@link https://workleap.github.io/wl-logging}
|
|
91
91
|
*/
|
|
92
|
-
debug(log?: string
|
|
92
|
+
debug(log?: string): void;
|
|
93
93
|
/**
|
|
94
94
|
* Write an information log. The log will be processed only if the logger LogLevel is >= information.
|
|
95
95
|
* @see {@link https://workleap.github.io/wl-logging}
|
|
96
96
|
*/
|
|
97
|
-
information(log?: string
|
|
97
|
+
information(log?: string): void;
|
|
98
98
|
/**
|
|
99
99
|
* Write a warning log. The log will be processed only if the logger LogLevel is >= warning.
|
|
100
100
|
* @see {@link https://workleap.github.io/wl-logging}
|
|
101
101
|
*/
|
|
102
|
-
warning(log?: string
|
|
102
|
+
warning(log?: string): void;
|
|
103
103
|
/**
|
|
104
104
|
* Write an error log. The log will be processed only if the logger LogLevel is >= error.
|
|
105
105
|
* @see {@link https://workleap.github.io/wl-logging}
|
|
106
106
|
*/
|
|
107
|
-
error(log?: string
|
|
107
|
+
error(log?: string): void;
|
|
108
108
|
/**
|
|
109
109
|
* Write a critical log. The log will be processed only if the logger LogLevel is >= critical.
|
|
110
110
|
* @see {@link https://workleap.github.io/wl-logging}
|
|
111
111
|
*/
|
|
112
|
-
critical(log?: string
|
|
112
|
+
critical(log?: string): void;
|
|
113
113
|
/**
|
|
114
114
|
* Start a new logging scope. The scope will inherit the LogLevel of the root logger.
|
|
115
115
|
* @see {@link https://workleap.github.io/wl-logging}
|
package/dist/LogRocketLogger.js
CHANGED
|
@@ -8,19 +8,42 @@ import logrocket from "logrocket";
|
|
|
8
8
|
;// CONCATENATED MODULE: ./src/LogRocketLogger.ts
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
function
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
11
|
+
function appendText(currentText, newText, options = {}) {
|
|
12
|
+
const { leadingSpace = true } = options;
|
|
13
|
+
if (currentText.length > 0) {
|
|
14
|
+
return `${currentText}${leadingSpace ? " " : ""}${newText}`;
|
|
15
|
+
}
|
|
16
|
+
return newText;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Formats an array of Segment objects into a list of log arguments.
|
|
20
|
+
*
|
|
21
|
+
* - Consecutive "text" segments are concatenated into a single string, separated by spaces (unless `leadingSpace` is false).
|
|
22
|
+
* - Non-"text" segments ("object", "error", "line-change") are added directly to the output array.
|
|
23
|
+
* - When a non-"text" segment is encountered, any buffered text is flushed to the output before adding the segment.
|
|
24
|
+
* - At the end, any remaining buffered text is flushed.
|
|
25
|
+
*/ function formatSegments(segments) {
|
|
26
|
+
const logs = [];
|
|
27
|
+
let textBuffer = "";
|
|
28
|
+
const flushText = ()=>{
|
|
29
|
+
if (textBuffer.length > 0) {
|
|
30
|
+
logs.push(textBuffer);
|
|
31
|
+
textBuffer = "";
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
segments.forEach((x)=>{
|
|
35
|
+
if (x.type === "text") {
|
|
36
|
+
textBuffer = appendText(textBuffer, x.value, {
|
|
37
|
+
leadingSpace: x.options?.leadingSpace
|
|
38
|
+
});
|
|
39
|
+
} else {
|
|
40
|
+
flushText();
|
|
41
|
+
logs.push(x.value);
|
|
21
42
|
}
|
|
22
|
-
|
|
23
|
-
|
|
43
|
+
});
|
|
44
|
+
// If the last segment is text, the text buffer hasn't been flushed.
|
|
45
|
+
flushText();
|
|
46
|
+
return logs;
|
|
24
47
|
}
|
|
25
48
|
/**
|
|
26
49
|
* An scope implementation for the LogRocket logger.
|
|
@@ -46,9 +69,9 @@ function parseSegments(segments) {
|
|
|
46
69
|
// Required closure to preserved the current log items for when they will be formatted when the scope is ended.
|
|
47
70
|
const segments = this.#segments;
|
|
48
71
|
this.#pendingLogs.push(()=>{
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
fct(...
|
|
72
|
+
const formattedSegments = formatSegments(segments);
|
|
73
|
+
formattedSegments.unshift(`(${this.#label})`);
|
|
74
|
+
fct(...formattedSegments);
|
|
52
75
|
});
|
|
53
76
|
}
|
|
54
77
|
this.#resetSegments();
|
|
@@ -56,10 +79,11 @@ function parseSegments(segments) {
|
|
|
56
79
|
}
|
|
57
80
|
/**
|
|
58
81
|
* @see {@link https://workleap.github.io/wl-logging}
|
|
59
|
-
*/ withText(text, options
|
|
82
|
+
*/ withText(text, options) {
|
|
60
83
|
if (text) {
|
|
61
84
|
this.#segments.push({
|
|
62
|
-
text,
|
|
85
|
+
type: "text",
|
|
86
|
+
value: text,
|
|
63
87
|
options
|
|
64
88
|
});
|
|
65
89
|
}
|
|
@@ -70,7 +94,8 @@ function parseSegments(segments) {
|
|
|
70
94
|
*/ withError(error) {
|
|
71
95
|
if (error) {
|
|
72
96
|
this.#segments.push({
|
|
73
|
-
error
|
|
97
|
+
type: "error",
|
|
98
|
+
value: error
|
|
74
99
|
});
|
|
75
100
|
}
|
|
76
101
|
return this;
|
|
@@ -80,7 +105,8 @@ function parseSegments(segments) {
|
|
|
80
105
|
*/ withObject(obj) {
|
|
81
106
|
if (obj) {
|
|
82
107
|
this.#segments.push({
|
|
83
|
-
|
|
108
|
+
type: "object",
|
|
109
|
+
value: obj
|
|
84
110
|
});
|
|
85
111
|
}
|
|
86
112
|
return this;
|
|
@@ -89,18 +115,19 @@ function parseSegments(segments) {
|
|
|
89
115
|
* @see {@link https://workleap.github.io/wl-logging}
|
|
90
116
|
*/ withLineChange() {
|
|
91
117
|
this.#segments.push({
|
|
92
|
-
|
|
118
|
+
type: "line-change",
|
|
119
|
+
value: "\r\n"
|
|
93
120
|
});
|
|
94
121
|
return this;
|
|
95
122
|
}
|
|
96
123
|
/**
|
|
97
124
|
* Write a debug log. The log will be processed only if the logger LogLevel is >= debug.
|
|
98
125
|
* @see {@link https://workleap.github.io/wl-logging}
|
|
99
|
-
*/ debug(log
|
|
126
|
+
*/ debug(log) {
|
|
100
127
|
if (log) {
|
|
101
128
|
this.#segments.push({
|
|
102
|
-
|
|
103
|
-
|
|
129
|
+
type: "text",
|
|
130
|
+
value: log
|
|
104
131
|
});
|
|
105
132
|
}
|
|
106
133
|
this.#log(logrocket.log, LogLevel.debug);
|
|
@@ -108,11 +135,11 @@ function parseSegments(segments) {
|
|
|
108
135
|
/**
|
|
109
136
|
* Write an information log. The log will be processed only if the logger LogLevel is >= information.
|
|
110
137
|
* @see {@link https://workleap.github.io/wl-logging}
|
|
111
|
-
*/ information(log
|
|
138
|
+
*/ information(log) {
|
|
112
139
|
if (log) {
|
|
113
140
|
this.#segments.push({
|
|
114
|
-
|
|
115
|
-
|
|
141
|
+
type: "text",
|
|
142
|
+
value: log
|
|
116
143
|
});
|
|
117
144
|
}
|
|
118
145
|
this.#log(logrocket.log, LogLevel.information);
|
|
@@ -120,11 +147,11 @@ function parseSegments(segments) {
|
|
|
120
147
|
/**
|
|
121
148
|
* Write a warning log. The log will be processed only if the logger LogLevel is >= warning.
|
|
122
149
|
* @see {@link https://workleap.github.io/wl-logging}
|
|
123
|
-
*/ warning(log
|
|
150
|
+
*/ warning(log) {
|
|
124
151
|
if (log) {
|
|
125
152
|
this.#segments.push({
|
|
126
|
-
|
|
127
|
-
|
|
153
|
+
type: "text",
|
|
154
|
+
value: log
|
|
128
155
|
});
|
|
129
156
|
}
|
|
130
157
|
this.#log(logrocket.warn, LogLevel.warning);
|
|
@@ -132,11 +159,11 @@ function parseSegments(segments) {
|
|
|
132
159
|
/**
|
|
133
160
|
* Write an error log. The log will be processed only if the logger LogLevel is >= error.
|
|
134
161
|
* @see {@link https://workleap.github.io/wl-logging}
|
|
135
|
-
*/ error(log
|
|
162
|
+
*/ error(log) {
|
|
136
163
|
if (log) {
|
|
137
164
|
this.#segments.push({
|
|
138
|
-
|
|
139
|
-
|
|
165
|
+
type: "text",
|
|
166
|
+
value: log
|
|
140
167
|
});
|
|
141
168
|
}
|
|
142
169
|
this.#log(logrocket.error, LogLevel.error);
|
|
@@ -144,11 +171,11 @@ function parseSegments(segments) {
|
|
|
144
171
|
/**
|
|
145
172
|
* Write a critical log. The log will be processed only if the logger LogLevel is >= critical.
|
|
146
173
|
* @see {@link https://workleap.github.io/wl-logging}
|
|
147
|
-
*/ critical(log
|
|
174
|
+
*/ critical(log) {
|
|
148
175
|
if (log) {
|
|
149
176
|
this.#segments.push({
|
|
150
|
-
|
|
151
|
-
|
|
177
|
+
type: "text",
|
|
178
|
+
value: log
|
|
152
179
|
});
|
|
153
180
|
}
|
|
154
181
|
this.#log(logrocket.error, LogLevel.critical);
|
|
@@ -188,8 +215,8 @@ function parseSegments(segments) {
|
|
|
188
215
|
#log(fct, threshold) {
|
|
189
216
|
if (this.#segments.length > 0) {
|
|
190
217
|
if (this.#logLevel <= threshold) {
|
|
191
|
-
const
|
|
192
|
-
fct(...
|
|
218
|
+
const formattedSegments = formatSegments(this.#segments);
|
|
219
|
+
fct(...formattedSegments);
|
|
193
220
|
}
|
|
194
221
|
this.#resetSegments();
|
|
195
222
|
}
|
|
@@ -201,10 +228,11 @@ function parseSegments(segments) {
|
|
|
201
228
|
}
|
|
202
229
|
/**
|
|
203
230
|
* @see {@link https://workleap.github.io/wl-logging}
|
|
204
|
-
*/ withText(text, options
|
|
231
|
+
*/ withText(text, options) {
|
|
205
232
|
if (text) {
|
|
206
233
|
this.#segments.push({
|
|
207
|
-
text,
|
|
234
|
+
type: "text",
|
|
235
|
+
value: text,
|
|
208
236
|
options
|
|
209
237
|
});
|
|
210
238
|
}
|
|
@@ -215,7 +243,8 @@ function parseSegments(segments) {
|
|
|
215
243
|
*/ withError(error) {
|
|
216
244
|
if (error) {
|
|
217
245
|
this.#segments.push({
|
|
218
|
-
error
|
|
246
|
+
type: "error",
|
|
247
|
+
value: error
|
|
219
248
|
});
|
|
220
249
|
}
|
|
221
250
|
return this;
|
|
@@ -225,7 +254,8 @@ function parseSegments(segments) {
|
|
|
225
254
|
*/ withObject(obj) {
|
|
226
255
|
if (obj) {
|
|
227
256
|
this.#segments.push({
|
|
228
|
-
|
|
257
|
+
type: "object",
|
|
258
|
+
value: obj
|
|
229
259
|
});
|
|
230
260
|
}
|
|
231
261
|
return this;
|
|
@@ -234,18 +264,19 @@ function parseSegments(segments) {
|
|
|
234
264
|
* @see {@link https://workleap.github.io/wl-logging}
|
|
235
265
|
*/ withLineChange() {
|
|
236
266
|
this.#segments.push({
|
|
237
|
-
|
|
267
|
+
type: "line-change",
|
|
268
|
+
value: "\r\n"
|
|
238
269
|
});
|
|
239
270
|
return this;
|
|
240
271
|
}
|
|
241
272
|
/**
|
|
242
273
|
* Write a debug log. The log will be processed only if the logger LogLevel is >= debug.
|
|
243
274
|
* @see {@link https://workleap.github.io/wl-logging}
|
|
244
|
-
*/ debug(log
|
|
275
|
+
*/ debug(log) {
|
|
245
276
|
if (log) {
|
|
246
277
|
this.#segments.push({
|
|
247
|
-
|
|
248
|
-
|
|
278
|
+
type: "text",
|
|
279
|
+
value: log
|
|
249
280
|
});
|
|
250
281
|
}
|
|
251
282
|
this.#log(logrocket.log, LogLevel.debug);
|
|
@@ -253,11 +284,11 @@ function parseSegments(segments) {
|
|
|
253
284
|
/**
|
|
254
285
|
* Write an information log. The log will be processed only if the logger LogLevel is >= information.
|
|
255
286
|
* @see {@link https://workleap.github.io/wl-logging}
|
|
256
|
-
*/ information(log
|
|
287
|
+
*/ information(log) {
|
|
257
288
|
if (log) {
|
|
258
289
|
this.#segments.push({
|
|
259
|
-
|
|
260
|
-
|
|
290
|
+
type: "text",
|
|
291
|
+
value: log
|
|
261
292
|
});
|
|
262
293
|
}
|
|
263
294
|
this.#log(logrocket.log, LogLevel.information);
|
|
@@ -265,11 +296,11 @@ function parseSegments(segments) {
|
|
|
265
296
|
/**
|
|
266
297
|
* Write a warning log. The log will be processed only if the logger LogLevel is >= warning.
|
|
267
298
|
* @see {@link https://workleap.github.io/wl-logging}
|
|
268
|
-
*/ warning(log
|
|
299
|
+
*/ warning(log) {
|
|
269
300
|
if (log) {
|
|
270
301
|
this.#segments.push({
|
|
271
|
-
|
|
272
|
-
|
|
302
|
+
type: "text",
|
|
303
|
+
value: log
|
|
273
304
|
});
|
|
274
305
|
}
|
|
275
306
|
this.#log(logrocket.warn, LogLevel.warning);
|
|
@@ -277,11 +308,11 @@ function parseSegments(segments) {
|
|
|
277
308
|
/**
|
|
278
309
|
* Write an error log. The log will be processed only if the logger LogLevel is >= error.
|
|
279
310
|
* @see {@link https://workleap.github.io/wl-logging}
|
|
280
|
-
*/ error(log
|
|
311
|
+
*/ error(log) {
|
|
281
312
|
if (log) {
|
|
282
313
|
this.#segments.push({
|
|
283
|
-
|
|
284
|
-
|
|
314
|
+
type: "text",
|
|
315
|
+
value: log
|
|
285
316
|
});
|
|
286
317
|
}
|
|
287
318
|
this.#log(logrocket.error, LogLevel.error);
|
|
@@ -289,11 +320,11 @@ function parseSegments(segments) {
|
|
|
289
320
|
/**
|
|
290
321
|
* Write a critical log. The log will be processed only if the logger LogLevel is >= critical.
|
|
291
322
|
* @see {@link https://workleap.github.io/wl-logging}
|
|
292
|
-
*/ critical(log
|
|
323
|
+
*/ critical(log) {
|
|
293
324
|
if (log) {
|
|
294
325
|
this.#segments.push({
|
|
295
|
-
|
|
296
|
-
|
|
326
|
+
type: "text",
|
|
327
|
+
value: log
|
|
297
328
|
});
|
|
298
329
|
}
|
|
299
330
|
this.#log(logrocket.error, LogLevel.critical);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LogRocketLogger.js","sources":["webpack://@workleap/logrocket/./src/LogRocketLogger.ts"],"sourcesContent":["import { type Logger, type LoggerOptions, type LoggerScope, type LoggerScopeEndOptions, LogLevel, type LogOptions, type Segment } from \"@workleap/logging\";\nimport LogRocket from \"logrocket\";\n\ntype LogFunction = (...rest: unknown[]) => void;\ntype PendingLog = () => void;\n\nfunction parseSegments(segments: Segment[]) {\n return segments.reduce<unknown[]>((acc, x) => {\n if (x.text) {\n acc.push(x.text);\n } else if (x.obj) {\n acc.push(x.obj);\n } else if (x.error) {\n acc.push(x.error);\n } else if (x.lineChange) {\n acc.push(\"\\r\\n\");\n }\n\n return acc;\n }, []);\n}\n\n/**\n * An scope implementation for the LogRocket logger.\n * @see {@link https://workleap.github.io/wl-telemetry}\n */\nexport class LogRocketLoggerScope implements LoggerScope {\n readonly #logLevel: LogLevel;\n readonly #label: string;\n\n #segments: Segment[] = [];\n #pendingLogs: PendingLog[] = [];\n #hasEnded: boolean = false;\n\n /**\n * @see {@link https://workleap.github.io/wl-logging}\n */\n constructor(label: string, logLevel: LogLevel) {\n this.#logLevel = logLevel;\n this.#label = label;\n }\n\n #resetSegments() {\n this.#segments = [];\n }\n\n #log(fct: LogFunction, threshold: LogLevel) {\n if (this.#segments.length > 0) {\n if (this.#logLevel <= threshold) {\n // Required closure to preserved the current log items for when they will be formatted when the scope is ended.\n const segments = this.#segments;\n\n this.#pendingLogs.push(() => {\n const parsedSegments = parseSegments(segments);\n parsedSegments.unshift(`(${this.#label})`);\n\n fct(...parsedSegments);\n });\n }\n\n this.#resetSegments();\n }\n }\n\n /**\n * @see {@link https://workleap.github.io/wl-logging}\n */\n withText(text?: string, options: LogOptions = {}) {\n if (text) {\n this.#segments.push({\n text,\n options\n });\n }\n\n return this;\n }\n\n /**\n * @see {@link https://workleap.github.io/wl-logging}\n */\n withError(error?: Error) {\n if (error) {\n this.#segments.push({\n error\n });\n }\n\n return this;\n }\n\n /**\n * @see {@link https://workleap.github.io/wl-logging}\n */\n withObject(obj?: unknown) {\n if (obj) {\n this.#segments.push({\n obj\n });\n }\n\n return this;\n }\n\n /**\n * @see {@link https://workleap.github.io/wl-logging}\n */\n withLineChange() {\n this.#segments.push({\n lineChange: true\n });\n\n return this;\n }\n\n /**\n * Write a debug log. The log will be processed only if the logger LogLevel is >= debug.\n * @see {@link https://workleap.github.io/wl-logging}\n */\n debug(log?: string, options?: LogOptions) {\n if (log) {\n this.#segments.push({\n text: log,\n options\n });\n }\n\n this.#log(LogRocket.log, LogLevel.debug);\n }\n\n /**\n * Write an information log. The log will be processed only if the logger LogLevel is >= information.\n * @see {@link https://workleap.github.io/wl-logging}\n */\n information(log?: string, options?: LogOptions) {\n if (log) {\n this.#segments.push({\n text: log,\n options\n });\n }\n\n this.#log(LogRocket.log, LogLevel.information);\n }\n\n /**\n * Write a warning log. The log will be processed only if the logger LogLevel is >= warning.\n * @see {@link https://workleap.github.io/wl-logging}\n */\n warning(log?: string, options?: LogOptions) {\n if (log) {\n this.#segments.push({\n text: log,\n options\n });\n }\n\n this.#log(LogRocket.warn, LogLevel.warning);\n }\n\n /**\n * Write an error log. The log will be processed only if the logger LogLevel is >= error.\n * @see {@link https://workleap.github.io/wl-logging}\n */\n error(log?: string, options?: LogOptions) {\n if (log) {\n this.#segments.push({\n text: log,\n options\n });\n }\n\n this.#log(LogRocket.error, LogLevel.error);\n }\n\n /**\n * Write a critical log. The log will be processed only if the logger LogLevel is >= critical.\n * @see {@link https://workleap.github.io/wl-logging}\n */\n critical(log?: string, options?: LogOptions) {\n if (log) {\n this.#segments.push({\n text: log,\n options\n });\n }\n\n this.#log(LogRocket.error, LogLevel.critical);\n }\n\n /**\n * @see {@link https://workleap.github.io/wl-logging}\n */\n end(options: LoggerScopeEndOptions = {}) {\n const {\n dismiss = false\n } = options;\n\n if (!this.#hasEnded) {\n this.#hasEnded = true;\n\n if (!dismiss) {\n if (this.#pendingLogs.length > 0) {\n this.#pendingLogs.forEach(x => {\n x();\n });\n\n this.#pendingLogs = [];\n }\n }\n }\n }\n}\n\n/**\n * A logger implementation for LogRocket.\n * @see {@link https://workleap.github.io/wl-telemetry}\n */\nexport class LogRocketLogger implements Logger {\n readonly #logLevel: LogLevel;\n #segments: Segment[] = [];\n\n /**\n * @see {@link https://workleap.github.io/wl-logging}\n */\n constructor(options: LoggerOptions = {}) {\n const {\n logLevel = LogLevel.debug\n } = options;\n\n this.#logLevel = logLevel;\n }\n\n #resetSegments() {\n this.#segments = [];\n }\n\n #log(fct: LogFunction, threshold: LogLevel) {\n if (this.#segments.length > 0) {\n if (this.#logLevel <= threshold) {\n const parsedSegments = parseSegments(this.#segments);\n\n fct(...parsedSegments);\n }\n\n this.#resetSegments();\n }\n }\n\n /**\n * @see {@link https://workleap.github.io/wl-logging}\n */\n getName() {\n return LogRocketLogger.name;\n }\n\n /**\n * @see {@link https://workleap.github.io/wl-logging}\n */\n withText(text?: string, options: LogOptions = {}) {\n if (text) {\n this.#segments.push({\n text,\n options\n });\n }\n\n return this;\n }\n\n /**\n * @see {@link https://workleap.github.io/wl-logging}\n */\n withError(error?: Error) {\n if (error) {\n this.#segments.push({\n error\n });\n }\n\n return this;\n }\n\n /**\n * @see {@link https://workleap.github.io/wl-logging}\n */\n withObject(obj?: unknown) {\n if (obj) {\n this.#segments.push({\n obj\n });\n }\n\n return this;\n }\n\n /**\n * @see {@link https://workleap.github.io/wl-logging}\n */\n withLineChange() {\n this.#segments.push({\n lineChange: true\n });\n\n return this;\n }\n\n /**\n * Write a debug log. The log will be processed only if the logger LogLevel is >= debug.\n * @see {@link https://workleap.github.io/wl-logging}\n */\n debug(log?: string, options?: LogOptions) {\n if (log) {\n this.#segments.push({\n text: log,\n options\n });\n }\n\n this.#log(LogRocket.log, LogLevel.debug);\n }\n\n /**\n * Write an information log. The log will be processed only if the logger LogLevel is >= information.\n * @see {@link https://workleap.github.io/wl-logging}\n */\n information(log?: string, options?: LogOptions) {\n if (log) {\n this.#segments.push({\n text: log,\n options\n });\n }\n\n this.#log(LogRocket.log, LogLevel.information);\n }\n\n /**\n * Write a warning log. The log will be processed only if the logger LogLevel is >= warning.\n * @see {@link https://workleap.github.io/wl-logging}\n */\n warning(log?: string, options?: LogOptions) {\n if (log) {\n this.#segments.push({\n text: log,\n options\n });\n }\n\n this.#log(LogRocket.warn, LogLevel.warning);\n }\n\n /**\n * Write an error log. The log will be processed only if the logger LogLevel is >= error.\n * @see {@link https://workleap.github.io/wl-logging}\n */\n error(log?: string, options?: LogOptions) {\n if (log) {\n this.#segments.push({\n text: log,\n options\n });\n }\n\n this.#log(LogRocket.error, LogLevel.error);\n }\n\n /**\n * Write a critical log. The log will be processed only if the logger LogLevel is >= critical.\n * @see {@link https://workleap.github.io/wl-logging}\n */\n critical(log?: string, options?: LogOptions) {\n if (log) {\n this.#segments.push({\n text: log,\n options\n });\n }\n\n this.#log(LogRocket.error, LogLevel.critical);\n }\n\n /**\n * Start a new logging scope. The scope will inherit the LogLevel of the root logger.\n * @see {@link https://workleap.github.io/wl-logging}\n */\n startScope(label: string) {\n return new LogRocketLoggerScope(label, this.#logLevel);\n }\n}\n"],"names":["LogLevel","LogRocket","parseSegments","segments","acc","x","LogRocketLoggerScope","label","logLevel","fct","threshold","parsedSegments","text","options","error","obj","log","dismiss","LogRocketLogger"],"mappings":";;;;;;;;AAA2J;AACzH;AAKlC,SAASE,cAAcC,QAAmB;IACtC,OAAOA,SAAS,MAAM,CAAY,CAACC,KAAKC;QACpC,IAAIA,EAAE,IAAI,EAAE;YACRD,IAAI,IAAI,CAACC,EAAE,IAAI;QACnB,OAAO,IAAIA,EAAE,GAAG,EAAE;YACdD,IAAI,IAAI,CAACC,EAAE,GAAG;QAClB,OAAO,IAAIA,EAAE,KAAK,EAAE;YAChBD,IAAI,IAAI,CAACC,EAAE,KAAK;QACpB,OAAO,IAAIA,EAAE,UAAU,EAAE;YACrBD,IAAI,IAAI,CAAC;QACb;QAEA,OAAOA;IACX,GAAG,EAAE;AACT;AAEA;;;CAGC,GACM,MAAME;IACA,SAAS,CAAW;IACpB,MAAM,CAAS;IAExB,SAAS,GAAc,EAAE,CAAC;IAC1B,YAAY,GAAiB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src/LogRocketLogger.ts"],"sourcesContent":["import { type Logger, type LoggerOptions, type LoggerScope, type LoggerScopeEndOptions, LogLevel, type LogOptions } from \"@workleap/logging\";\nimport LogRocket from \"logrocket\";\n\ninterface Segment {\n type: \"text\" | \"object\" | \"error\" | \"line-change\";\n value: unknown;\n options?: LogOptions;\n}\n\nfunction appendText(currentText: string, newText: string, options: { leadingSpace?: boolean } = {}) {\n const {\n leadingSpace = true\n } = options;\n\n if (currentText.length > 0) {\n return `${currentText}${leadingSpace ? \" \" : \"\"}${newText}`;\n }\n\n return newText;\n}\n\n/**\n * Formats an array of Segment objects into a list of log arguments.\n *\n * - Consecutive \"text\" segments are concatenated into a single string, separated by spaces (unless `leadingSpace` is false).\n * - Non-\"text\" segments (\"object\", \"error\", \"line-change\") are added directly to the output array.\n * - When a non-\"text\" segment is encountered, any buffered text is flushed to the output before adding the segment.\n * - At the end, any remaining buffered text is flushed.\n */\nfunction formatSegments(segments: Segment[]) {\n const logs: unknown[] = [];\n\n let textBuffer = \"\";\n\n const flushText = () => {\n if (textBuffer.length > 0) {\n logs.push(textBuffer);\n\n textBuffer = \"\";\n }\n };\n\n segments.forEach(x => {\n if (x.type === \"text\") {\n textBuffer = appendText(textBuffer, x.value as string, {\n leadingSpace: x.options?.leadingSpace\n });\n } else {\n flushText();\n\n logs.push(x.value);\n }\n });\n\n // If the last segment is text, the text buffer hasn't been flushed.\n flushText();\n\n return logs;\n}\n\ntype LogFunction = (...rest: unknown[]) => void;\ntype PendingLog = () => void;\n\n/**\n * An scope implementation for the LogRocket logger.\n * @see {@link https://workleap.github.io/wl-telemetry}\n */\nexport class LogRocketLoggerScope implements LoggerScope {\n readonly #logLevel: LogLevel;\n readonly #label: string;\n\n #segments: Segment[] = [];\n #pendingLogs: PendingLog[] = [];\n #hasEnded: boolean = false;\n\n /**\n * @see {@link https://workleap.github.io/wl-logging}\n */\n constructor(label: string, logLevel: LogLevel) {\n this.#logLevel = logLevel;\n this.#label = label;\n }\n\n #resetSegments() {\n this.#segments = [];\n }\n\n #log(fct: LogFunction, threshold: LogLevel) {\n if (this.#segments.length > 0) {\n if (this.#logLevel <= threshold) {\n // Required closure to preserved the current log items for when they will be formatted when the scope is ended.\n const segments = this.#segments;\n\n this.#pendingLogs.push(() => {\n const formattedSegments = formatSegments(segments);\n formattedSegments.unshift(`(${this.#label})`);\n\n fct(...formattedSegments);\n });\n }\n\n this.#resetSegments();\n }\n }\n\n /**\n * @see {@link https://workleap.github.io/wl-logging}\n */\n withText(text?: string, options?: Omit<LogOptions, \"style\">) {\n if (text) {\n this.#segments.push({\n type: \"text\",\n value: text,\n options\n });\n }\n\n return this;\n }\n\n /**\n * @see {@link https://workleap.github.io/wl-logging}\n */\n withError(error?: Error) {\n if (error) {\n this.#segments.push({\n type: \"error\",\n value: error\n });\n }\n\n return this;\n }\n\n /**\n * @see {@link https://workleap.github.io/wl-logging}\n */\n withObject(obj?: unknown) {\n if (obj) {\n this.#segments.push({\n type: \"object\",\n value: obj\n });\n }\n\n return this;\n }\n\n /**\n * @see {@link https://workleap.github.io/wl-logging}\n */\n withLineChange() {\n this.#segments.push({\n type: \"line-change\",\n value: \"\\r\\n\"\n });\n\n return this;\n }\n\n /**\n * Write a debug log. The log will be processed only if the logger LogLevel is >= debug.\n * @see {@link https://workleap.github.io/wl-logging}\n */\n debug(log?: string) {\n if (log) {\n this.#segments.push({\n type: \"text\",\n value: log\n });\n }\n\n this.#log(LogRocket.log, LogLevel.debug);\n }\n\n /**\n * Write an information log. The log will be processed only if the logger LogLevel is >= information.\n * @see {@link https://workleap.github.io/wl-logging}\n */\n information(log?: string) {\n if (log) {\n this.#segments.push({\n type: \"text\",\n value: log\n });\n }\n\n this.#log(LogRocket.log, LogLevel.information);\n }\n\n /**\n * Write a warning log. The log will be processed only if the logger LogLevel is >= warning.\n * @see {@link https://workleap.github.io/wl-logging}\n */\n warning(log?: string) {\n if (log) {\n this.#segments.push({\n type: \"text\",\n value: log\n });\n }\n\n this.#log(LogRocket.warn, LogLevel.warning);\n }\n\n /**\n * Write an error log. The log will be processed only if the logger LogLevel is >= error.\n * @see {@link https://workleap.github.io/wl-logging}\n */\n error(log?: string) {\n if (log) {\n this.#segments.push({\n type: \"text\",\n value: log\n });\n }\n\n this.#log(LogRocket.error, LogLevel.error);\n }\n\n /**\n * Write a critical log. The log will be processed only if the logger LogLevel is >= critical.\n * @see {@link https://workleap.github.io/wl-logging}\n */\n critical(log?: string) {\n if (log) {\n this.#segments.push({\n type: \"text\",\n value: log\n });\n }\n\n this.#log(LogRocket.error, LogLevel.critical);\n }\n\n /**\n * @see {@link https://workleap.github.io/wl-logging}\n */\n end(options: LoggerScopeEndOptions = {}) {\n const {\n dismiss = false\n } = options;\n\n if (!this.#hasEnded) {\n this.#hasEnded = true;\n\n if (!dismiss) {\n if (this.#pendingLogs.length > 0) {\n this.#pendingLogs.forEach(x => {\n x();\n });\n\n this.#pendingLogs = [];\n }\n }\n }\n }\n}\n\n/**\n * A logger implementation for LogRocket.\n * @see {@link https://workleap.github.io/wl-telemetry}\n */\nexport class LogRocketLogger implements Logger {\n readonly #logLevel: LogLevel;\n #segments: Segment[] = [];\n\n /**\n * @see {@link https://workleap.github.io/wl-logging}\n */\n constructor(options: LoggerOptions = {}) {\n const {\n logLevel = LogLevel.debug\n } = options;\n\n this.#logLevel = logLevel;\n }\n\n #resetSegments() {\n this.#segments = [];\n }\n\n #log(fct: LogFunction, threshold: LogLevel) {\n if (this.#segments.length > 0) {\n if (this.#logLevel <= threshold) {\n const formattedSegments = formatSegments(this.#segments);\n\n fct(...formattedSegments);\n }\n\n this.#resetSegments();\n }\n }\n\n /**\n * @see {@link https://workleap.github.io/wl-logging}\n */\n getName() {\n return LogRocketLogger.name;\n }\n\n /**\n * @see {@link https://workleap.github.io/wl-logging}\n */\n withText(text?: string, options?: Omit<LogOptions, \"style\">) {\n if (text) {\n this.#segments.push({\n type: \"text\",\n value: text,\n options\n });\n }\n\n return this;\n }\n\n /**\n * @see {@link https://workleap.github.io/wl-logging}\n */\n withError(error?: Error) {\n if (error) {\n this.#segments.push({\n type: \"error\",\n value: error\n });\n }\n\n return this;\n }\n\n /**\n * @see {@link https://workleap.github.io/wl-logging}\n */\n withObject(obj?: unknown) {\n if (obj) {\n this.#segments.push({\n type: \"object\",\n value: obj\n });\n }\n\n return this;\n }\n\n /**\n * @see {@link https://workleap.github.io/wl-logging}\n */\n withLineChange() {\n this.#segments.push({\n type: \"line-change\",\n value: \"\\r\\n\"\n });\n\n return this;\n }\n\n /**\n * Write a debug log. The log will be processed only if the logger LogLevel is >= debug.\n * @see {@link https://workleap.github.io/wl-logging}\n */\n debug(log?: string) {\n if (log) {\n this.#segments.push({\n type: \"text\",\n value: log\n });\n }\n\n this.#log(LogRocket.log, LogLevel.debug);\n }\n\n /**\n * Write an information log. The log will be processed only if the logger LogLevel is >= information.\n * @see {@link https://workleap.github.io/wl-logging}\n */\n information(log?: string) {\n if (log) {\n this.#segments.push({\n type: \"text\",\n value: log\n });\n }\n\n this.#log(LogRocket.log, LogLevel.information);\n }\n\n /**\n * Write a warning log. The log will be processed only if the logger LogLevel is >= warning.\n * @see {@link https://workleap.github.io/wl-logging}\n */\n warning(log?: string) {\n if (log) {\n this.#segments.push({\n type: \"text\",\n value: log\n });\n }\n\n this.#log(LogRocket.warn, LogLevel.warning);\n }\n\n /**\n * Write an error log. The log will be processed only if the logger LogLevel is >= error.\n * @see {@link https://workleap.github.io/wl-logging}\n */\n error(log?: string) {\n if (log) {\n this.#segments.push({\n type: \"text\",\n value: log\n });\n }\n\n this.#log(LogRocket.error, LogLevel.error);\n }\n\n /**\n * Write a critical log. The log will be processed only if the logger LogLevel is >= critical.\n * @see {@link https://workleap.github.io/wl-logging}\n */\n critical(log?: string) {\n if (log) {\n this.#segments.push({\n type: \"text\",\n value: log\n });\n }\n\n this.#log(LogRocket.error, LogLevel.critical);\n }\n\n /**\n * Start a new logging scope. The scope will inherit the LogLevel of the root logger.\n * @see {@link https://workleap.github.io/wl-logging}\n */\n startScope(label: string) {\n return new LogRocketLoggerScope(label, this.#logLevel);\n }\n}\n"],"names":["LogLevel","LogRocket","appendText","currentText","newText","options","leadingSpace","formatSegments","segments","logs","textBuffer","flushText","x","LogRocketLoggerScope","label","logLevel","fct","threshold","formattedSegments","text","error","obj","log","dismiss","LogRocketLogger"],"mappings":";;;;;;;;AAA6I;AAC3G;AAQlC,SAASE,WAAWC,WAAmB,EAAEC,OAAe,EAAEC,UAAsC,CAAC,CAAC;IAC9F,MAAM,EACFC,eAAe,IAAI,EACtB,GAAGD;IAEJ,IAAIF,YAAY,MAAM,GAAG,GAAG;QACxB,OAAO,GAAGA,cAAcG,eAAe,MAAM,KAAKF,SAAS;IAC/D;IAEA,OAAOA;AACX;AAEA;;;;;;;CAOC,GACD,SAASG,eAAeC,QAAmB;IACvC,MAAMC,OAAkB,EAAE;IAE1B,IAAIC,aAAa;IAEjB,MAAMC,YAAY;QACd,IAAID,WAAW,MAAM,GAAG,GAAG;YACvBD,KAAK,IAAI,CAACC;YAEVA,aAAa;QACjB;IACJ;IAEAF,SAAS,OAAO,CAACI,CAAAA;QACb,IAAIA,EAAE,IAAI,KAAK,QAAQ;YACnBF,aAAaR,WAAWQ,YAAYE,EAAE,KAAK,EAAY;gBACnD,cAAcA,EAAE,OAAO,EAAE;YAC7B;QACJ,OAAO;YACHD;YAEAF,KAAK,IAAI,CAACG,EAAE,KAAK;QACrB;IACJ;IAEA,oEAAoE;IACpED;IAEA,OAAOF;AACX;AAKA;;;CAGC,GACM,MAAMI;IACA,SAAS,CAAW;IACpB,MAAM,CAAS;IAExB,SAAS,GAAc,EAAE,CAAC;IAC1B,YAAY,GAAiB,EAAE,CAAC;IAChC,SAAS,GAAY,MAAM;IAE3B;;KAEC,GACD,YAAYC,KAAa,EAAEC,QAAkB,CAAE;QAC3C,IAAI,CAAC,SAAS,GAAGA;QACjB,IAAI,CAAC,MAAM,GAAGD;IAClB;IAEA,cAAc;QACV,IAAI,CAAC,SAAS,GAAG,EAAE;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AOA;YACX;QACJ;QAEA,IAAI,CAAC,IAAI,CAACrB,aAAa,EAAED,cAAc;IAC3C;IAEA;;;KAGC,GACD,YAAYsB,GAAY,EAAE;QACtB,IAAIA,KAAK;YACL,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;gBAChB,MAAM;gBACN,OAAOA;YACX;QACJ;QAEA,IAAI,CAAC,IAAI,CAACrB,aAAa,EAAED,oBAAoB;IACjD;IAEA;;;KAGC,GACD,QAAQsB,GAAY,EAAE;QAClB,IAAIA,KAAK;YACL,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;gBAChB,MAAM;gBACN,OAAOA;YACX;QACJ;QAEA,IAAI,CAAC,IAAI,CAACrB,cAAc,EAAED,gBAAgB;IAC9C;IAEA;;;KAGC,GACD,MAAMsB,GAAY,EAAE;QAChB,IAAIA,KAAK;YACL,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;gBAChB,MAAM;gBACN,OAAOA;YACX;QACJ;QAEA,IAAI,CAAC,IAAI,CAACrB,eAAe,EAAED,cAAc;IAC7C;IAEA;;;KAGC,GACD,SAASsB,GAAY,EAAE;QACnB,IAAIA,KAAK;YACL,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;gBAChB,MAAM;gBACN,OAAOA;YACX;QACJ;QAEA,IAAI,CAAC,IAAI,CAACrB,eAAe,EAAED,iBAAiB;IAChD;IAEA;;;KAGC,GACD,WAAWc,KAAa,EAAE;QACtB,OAAO,IAAID,qBAAqBC,OAAO,IAAI,CAAC,SAAS;IACzD;AACJ"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@workleap/logrocket",
|
|
3
3
|
"author": "Workleap",
|
|
4
|
-
"version": "1.2.
|
|
4
|
+
"version": "1.2.5",
|
|
5
5
|
"description": "A package containing utilities for LogRocket.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"repository": {
|
|
@@ -31,9 +31,9 @@
|
|
|
31
31
|
"logrocket": "^10.1.0"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@workleap/logging": "^1.2.
|
|
34
|
+
"@workleap/logging": "^1.2.5",
|
|
35
35
|
"logrocket-fuzzy-search-sanitizer": "0.0.2",
|
|
36
|
-
"@workleap/telemetry": "1.1.
|
|
36
|
+
"@workleap/telemetry": "1.1.6"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@rsbuild/core": "1.4.6",
|
package/src/LogRocketLogger.ts
CHANGED
|
@@ -1,25 +1,66 @@
|
|
|
1
|
-
import { type Logger, type LoggerOptions, type LoggerScope, type LoggerScopeEndOptions, LogLevel, type LogOptions
|
|
1
|
+
import { type Logger, type LoggerOptions, type LoggerScope, type LoggerScopeEndOptions, LogLevel, type LogOptions } from "@workleap/logging";
|
|
2
2
|
import LogRocket from "logrocket";
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
type
|
|
4
|
+
interface Segment {
|
|
5
|
+
type: "text" | "object" | "error" | "line-change";
|
|
6
|
+
value: unknown;
|
|
7
|
+
options?: LogOptions;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function appendText(currentText: string, newText: string, options: { leadingSpace?: boolean } = {}) {
|
|
11
|
+
const {
|
|
12
|
+
leadingSpace = true
|
|
13
|
+
} = options;
|
|
14
|
+
|
|
15
|
+
if (currentText.length > 0) {
|
|
16
|
+
return `${currentText}${leadingSpace ? " " : ""}${newText}`;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return newText;
|
|
20
|
+
}
|
|
6
21
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Formats an array of Segment objects into a list of log arguments.
|
|
24
|
+
*
|
|
25
|
+
* - Consecutive "text" segments are concatenated into a single string, separated by spaces (unless `leadingSpace` is false).
|
|
26
|
+
* - Non-"text" segments ("object", "error", "line-change") are added directly to the output array.
|
|
27
|
+
* - When a non-"text" segment is encountered, any buffered text is flushed to the output before adding the segment.
|
|
28
|
+
* - At the end, any remaining buffered text is flushed.
|
|
29
|
+
*/
|
|
30
|
+
function formatSegments(segments: Segment[]) {
|
|
31
|
+
const logs: unknown[] = [];
|
|
32
|
+
|
|
33
|
+
let textBuffer = "";
|
|
34
|
+
|
|
35
|
+
const flushText = () => {
|
|
36
|
+
if (textBuffer.length > 0) {
|
|
37
|
+
logs.push(textBuffer);
|
|
38
|
+
|
|
39
|
+
textBuffer = "";
|
|
17
40
|
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
segments.forEach(x => {
|
|
44
|
+
if (x.type === "text") {
|
|
45
|
+
textBuffer = appendText(textBuffer, x.value as string, {
|
|
46
|
+
leadingSpace: x.options?.leadingSpace
|
|
47
|
+
});
|
|
48
|
+
} else {
|
|
49
|
+
flushText();
|
|
18
50
|
|
|
19
|
-
|
|
20
|
-
|
|
51
|
+
logs.push(x.value);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// If the last segment is text, the text buffer hasn't been flushed.
|
|
56
|
+
flushText();
|
|
57
|
+
|
|
58
|
+
return logs;
|
|
21
59
|
}
|
|
22
60
|
|
|
61
|
+
type LogFunction = (...rest: unknown[]) => void;
|
|
62
|
+
type PendingLog = () => void;
|
|
63
|
+
|
|
23
64
|
/**
|
|
24
65
|
* An scope implementation for the LogRocket logger.
|
|
25
66
|
* @see {@link https://workleap.github.io/wl-telemetry}
|
|
@@ -51,10 +92,10 @@ export class LogRocketLoggerScope implements LoggerScope {
|
|
|
51
92
|
const segments = this.#segments;
|
|
52
93
|
|
|
53
94
|
this.#pendingLogs.push(() => {
|
|
54
|
-
const
|
|
55
|
-
|
|
95
|
+
const formattedSegments = formatSegments(segments);
|
|
96
|
+
formattedSegments.unshift(`(${this.#label})`);
|
|
56
97
|
|
|
57
|
-
fct(...
|
|
98
|
+
fct(...formattedSegments);
|
|
58
99
|
});
|
|
59
100
|
}
|
|
60
101
|
|
|
@@ -65,10 +106,11 @@ export class LogRocketLoggerScope implements LoggerScope {
|
|
|
65
106
|
/**
|
|
66
107
|
* @see {@link https://workleap.github.io/wl-logging}
|
|
67
108
|
*/
|
|
68
|
-
withText(text?: string, options
|
|
109
|
+
withText(text?: string, options?: Omit<LogOptions, "style">) {
|
|
69
110
|
if (text) {
|
|
70
111
|
this.#segments.push({
|
|
71
|
-
text,
|
|
112
|
+
type: "text",
|
|
113
|
+
value: text,
|
|
72
114
|
options
|
|
73
115
|
});
|
|
74
116
|
}
|
|
@@ -82,7 +124,8 @@ export class LogRocketLoggerScope implements LoggerScope {
|
|
|
82
124
|
withError(error?: Error) {
|
|
83
125
|
if (error) {
|
|
84
126
|
this.#segments.push({
|
|
85
|
-
error
|
|
127
|
+
type: "error",
|
|
128
|
+
value: error
|
|
86
129
|
});
|
|
87
130
|
}
|
|
88
131
|
|
|
@@ -95,7 +138,8 @@ export class LogRocketLoggerScope implements LoggerScope {
|
|
|
95
138
|
withObject(obj?: unknown) {
|
|
96
139
|
if (obj) {
|
|
97
140
|
this.#segments.push({
|
|
98
|
-
|
|
141
|
+
type: "object",
|
|
142
|
+
value: obj
|
|
99
143
|
});
|
|
100
144
|
}
|
|
101
145
|
|
|
@@ -107,7 +151,8 @@ export class LogRocketLoggerScope implements LoggerScope {
|
|
|
107
151
|
*/
|
|
108
152
|
withLineChange() {
|
|
109
153
|
this.#segments.push({
|
|
110
|
-
|
|
154
|
+
type: "line-change",
|
|
155
|
+
value: "\r\n"
|
|
111
156
|
});
|
|
112
157
|
|
|
113
158
|
return this;
|
|
@@ -117,11 +162,11 @@ export class LogRocketLoggerScope implements LoggerScope {
|
|
|
117
162
|
* Write a debug log. The log will be processed only if the logger LogLevel is >= debug.
|
|
118
163
|
* @see {@link https://workleap.github.io/wl-logging}
|
|
119
164
|
*/
|
|
120
|
-
debug(log?: string
|
|
165
|
+
debug(log?: string) {
|
|
121
166
|
if (log) {
|
|
122
167
|
this.#segments.push({
|
|
123
|
-
|
|
124
|
-
|
|
168
|
+
type: "text",
|
|
169
|
+
value: log
|
|
125
170
|
});
|
|
126
171
|
}
|
|
127
172
|
|
|
@@ -132,11 +177,11 @@ export class LogRocketLoggerScope implements LoggerScope {
|
|
|
132
177
|
* Write an information log. The log will be processed only if the logger LogLevel is >= information.
|
|
133
178
|
* @see {@link https://workleap.github.io/wl-logging}
|
|
134
179
|
*/
|
|
135
|
-
information(log?: string
|
|
180
|
+
information(log?: string) {
|
|
136
181
|
if (log) {
|
|
137
182
|
this.#segments.push({
|
|
138
|
-
|
|
139
|
-
|
|
183
|
+
type: "text",
|
|
184
|
+
value: log
|
|
140
185
|
});
|
|
141
186
|
}
|
|
142
187
|
|
|
@@ -147,11 +192,11 @@ export class LogRocketLoggerScope implements LoggerScope {
|
|
|
147
192
|
* Write a warning log. The log will be processed only if the logger LogLevel is >= warning.
|
|
148
193
|
* @see {@link https://workleap.github.io/wl-logging}
|
|
149
194
|
*/
|
|
150
|
-
warning(log?: string
|
|
195
|
+
warning(log?: string) {
|
|
151
196
|
if (log) {
|
|
152
197
|
this.#segments.push({
|
|
153
|
-
|
|
154
|
-
|
|
198
|
+
type: "text",
|
|
199
|
+
value: log
|
|
155
200
|
});
|
|
156
201
|
}
|
|
157
202
|
|
|
@@ -162,11 +207,11 @@ export class LogRocketLoggerScope implements LoggerScope {
|
|
|
162
207
|
* Write an error log. The log will be processed only if the logger LogLevel is >= error.
|
|
163
208
|
* @see {@link https://workleap.github.io/wl-logging}
|
|
164
209
|
*/
|
|
165
|
-
error(log?: string
|
|
210
|
+
error(log?: string) {
|
|
166
211
|
if (log) {
|
|
167
212
|
this.#segments.push({
|
|
168
|
-
|
|
169
|
-
|
|
213
|
+
type: "text",
|
|
214
|
+
value: log
|
|
170
215
|
});
|
|
171
216
|
}
|
|
172
217
|
|
|
@@ -177,11 +222,11 @@ export class LogRocketLoggerScope implements LoggerScope {
|
|
|
177
222
|
* Write a critical log. The log will be processed only if the logger LogLevel is >= critical.
|
|
178
223
|
* @see {@link https://workleap.github.io/wl-logging}
|
|
179
224
|
*/
|
|
180
|
-
critical(log?: string
|
|
225
|
+
critical(log?: string) {
|
|
181
226
|
if (log) {
|
|
182
227
|
this.#segments.push({
|
|
183
|
-
|
|
184
|
-
|
|
228
|
+
type: "text",
|
|
229
|
+
value: log
|
|
185
230
|
});
|
|
186
231
|
}
|
|
187
232
|
|
|
@@ -238,9 +283,9 @@ export class LogRocketLogger implements Logger {
|
|
|
238
283
|
#log(fct: LogFunction, threshold: LogLevel) {
|
|
239
284
|
if (this.#segments.length > 0) {
|
|
240
285
|
if (this.#logLevel <= threshold) {
|
|
241
|
-
const
|
|
286
|
+
const formattedSegments = formatSegments(this.#segments);
|
|
242
287
|
|
|
243
|
-
fct(...
|
|
288
|
+
fct(...formattedSegments);
|
|
244
289
|
}
|
|
245
290
|
|
|
246
291
|
this.#resetSegments();
|
|
@@ -257,10 +302,11 @@ export class LogRocketLogger implements Logger {
|
|
|
257
302
|
/**
|
|
258
303
|
* @see {@link https://workleap.github.io/wl-logging}
|
|
259
304
|
*/
|
|
260
|
-
withText(text?: string, options
|
|
305
|
+
withText(text?: string, options?: Omit<LogOptions, "style">) {
|
|
261
306
|
if (text) {
|
|
262
307
|
this.#segments.push({
|
|
263
|
-
text,
|
|
308
|
+
type: "text",
|
|
309
|
+
value: text,
|
|
264
310
|
options
|
|
265
311
|
});
|
|
266
312
|
}
|
|
@@ -274,7 +320,8 @@ export class LogRocketLogger implements Logger {
|
|
|
274
320
|
withError(error?: Error) {
|
|
275
321
|
if (error) {
|
|
276
322
|
this.#segments.push({
|
|
277
|
-
error
|
|
323
|
+
type: "error",
|
|
324
|
+
value: error
|
|
278
325
|
});
|
|
279
326
|
}
|
|
280
327
|
|
|
@@ -287,7 +334,8 @@ export class LogRocketLogger implements Logger {
|
|
|
287
334
|
withObject(obj?: unknown) {
|
|
288
335
|
if (obj) {
|
|
289
336
|
this.#segments.push({
|
|
290
|
-
|
|
337
|
+
type: "object",
|
|
338
|
+
value: obj
|
|
291
339
|
});
|
|
292
340
|
}
|
|
293
341
|
|
|
@@ -299,7 +347,8 @@ export class LogRocketLogger implements Logger {
|
|
|
299
347
|
*/
|
|
300
348
|
withLineChange() {
|
|
301
349
|
this.#segments.push({
|
|
302
|
-
|
|
350
|
+
type: "line-change",
|
|
351
|
+
value: "\r\n"
|
|
303
352
|
});
|
|
304
353
|
|
|
305
354
|
return this;
|
|
@@ -309,11 +358,11 @@ export class LogRocketLogger implements Logger {
|
|
|
309
358
|
* Write a debug log. The log will be processed only if the logger LogLevel is >= debug.
|
|
310
359
|
* @see {@link https://workleap.github.io/wl-logging}
|
|
311
360
|
*/
|
|
312
|
-
debug(log?: string
|
|
361
|
+
debug(log?: string) {
|
|
313
362
|
if (log) {
|
|
314
363
|
this.#segments.push({
|
|
315
|
-
|
|
316
|
-
|
|
364
|
+
type: "text",
|
|
365
|
+
value: log
|
|
317
366
|
});
|
|
318
367
|
}
|
|
319
368
|
|
|
@@ -324,11 +373,11 @@ export class LogRocketLogger implements Logger {
|
|
|
324
373
|
* Write an information log. The log will be processed only if the logger LogLevel is >= information.
|
|
325
374
|
* @see {@link https://workleap.github.io/wl-logging}
|
|
326
375
|
*/
|
|
327
|
-
information(log?: string
|
|
376
|
+
information(log?: string) {
|
|
328
377
|
if (log) {
|
|
329
378
|
this.#segments.push({
|
|
330
|
-
|
|
331
|
-
|
|
379
|
+
type: "text",
|
|
380
|
+
value: log
|
|
332
381
|
});
|
|
333
382
|
}
|
|
334
383
|
|
|
@@ -339,11 +388,11 @@ export class LogRocketLogger implements Logger {
|
|
|
339
388
|
* Write a warning log. The log will be processed only if the logger LogLevel is >= warning.
|
|
340
389
|
* @see {@link https://workleap.github.io/wl-logging}
|
|
341
390
|
*/
|
|
342
|
-
warning(log?: string
|
|
391
|
+
warning(log?: string) {
|
|
343
392
|
if (log) {
|
|
344
393
|
this.#segments.push({
|
|
345
|
-
|
|
346
|
-
|
|
394
|
+
type: "text",
|
|
395
|
+
value: log
|
|
347
396
|
});
|
|
348
397
|
}
|
|
349
398
|
|
|
@@ -354,11 +403,11 @@ export class LogRocketLogger implements Logger {
|
|
|
354
403
|
* Write an error log. The log will be processed only if the logger LogLevel is >= error.
|
|
355
404
|
* @see {@link https://workleap.github.io/wl-logging}
|
|
356
405
|
*/
|
|
357
|
-
error(log?: string
|
|
406
|
+
error(log?: string) {
|
|
358
407
|
if (log) {
|
|
359
408
|
this.#segments.push({
|
|
360
|
-
|
|
361
|
-
|
|
409
|
+
type: "text",
|
|
410
|
+
value: log
|
|
362
411
|
});
|
|
363
412
|
}
|
|
364
413
|
|
|
@@ -369,11 +418,11 @@ export class LogRocketLogger implements Logger {
|
|
|
369
418
|
* Write a critical log. The log will be processed only if the logger LogLevel is >= critical.
|
|
370
419
|
* @see {@link https://workleap.github.io/wl-logging}
|
|
371
420
|
*/
|
|
372
|
-
critical(log?: string
|
|
421
|
+
critical(log?: string) {
|
|
373
422
|
if (log) {
|
|
374
423
|
this.#segments.push({
|
|
375
|
-
|
|
376
|
-
|
|
424
|
+
type: "text",
|
|
425
|
+
value: log
|
|
377
426
|
});
|
|
378
427
|
}
|
|
379
428
|
|