@workleap/logrocket 1.2.4 → 1.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/dist/LogRocketLogger.d.ts +3 -3
- package/dist/LogRocketLogger.js +48 -9
- package/dist/LogRocketLogger.js.map +1 -1
- package/package.json +3 -3
- package/src/LogRocketLogger.ts +64 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
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
|
+
|
|
3
12
|
## 1.2.4
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Logger, type LoggerOptions, type LoggerScope, type LoggerScopeEndOptions, LogLevel } from "@workleap/logging";
|
|
1
|
+
import { type Logger, type LoggerOptions, type LoggerScope, type LoggerScopeEndOptions, LogLevel, type LogOptions } from "@workleap/logging";
|
|
2
2
|
/**
|
|
3
3
|
* An scope implementation for the LogRocket logger.
|
|
4
4
|
* @see {@link https://workleap.github.io/wl-telemetry}
|
|
@@ -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): this;
|
|
15
|
+
withText(text?: string, options?: Omit<LogOptions, "style">): this;
|
|
16
16
|
/**
|
|
17
17
|
* @see {@link https://workleap.github.io/wl-logging}
|
|
18
18
|
*/
|
|
@@ -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): this;
|
|
75
|
+
withText(text?: string, options?: Omit<LogOptions, "style">): this;
|
|
76
76
|
/**
|
|
77
77
|
* @see {@link https://workleap.github.io/wl-logging}
|
|
78
78
|
*/
|
package/dist/LogRocketLogger.js
CHANGED
|
@@ -8,6 +8,43 @@ import logrocket from "logrocket";
|
|
|
8
8
|
;// CONCATENATED MODULE: ./src/LogRocketLogger.ts
|
|
9
9
|
|
|
10
10
|
|
|
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);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
// If the last segment is text, the text buffer hasn't been flushed.
|
|
45
|
+
flushText();
|
|
46
|
+
return logs;
|
|
47
|
+
}
|
|
11
48
|
/**
|
|
12
49
|
* An scope implementation for the LogRocket logger.
|
|
13
50
|
* @see {@link https://workleap.github.io/wl-telemetry}
|
|
@@ -32,9 +69,9 @@ import logrocket from "logrocket";
|
|
|
32
69
|
// Required closure to preserved the current log items for when they will be formatted when the scope is ended.
|
|
33
70
|
const segments = this.#segments;
|
|
34
71
|
this.#pendingLogs.push(()=>{
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
fct(...
|
|
72
|
+
const formattedSegments = formatSegments(segments);
|
|
73
|
+
formattedSegments.unshift(`(${this.#label})`);
|
|
74
|
+
fct(...formattedSegments);
|
|
38
75
|
});
|
|
39
76
|
}
|
|
40
77
|
this.#resetSegments();
|
|
@@ -42,11 +79,12 @@ import logrocket from "logrocket";
|
|
|
42
79
|
}
|
|
43
80
|
/**
|
|
44
81
|
* @see {@link https://workleap.github.io/wl-logging}
|
|
45
|
-
*/ withText(text) {
|
|
82
|
+
*/ withText(text, options) {
|
|
46
83
|
if (text) {
|
|
47
84
|
this.#segments.push({
|
|
48
85
|
type: "text",
|
|
49
|
-
value: text
|
|
86
|
+
value: text,
|
|
87
|
+
options
|
|
50
88
|
});
|
|
51
89
|
}
|
|
52
90
|
return this;
|
|
@@ -177,8 +215,8 @@ import logrocket from "logrocket";
|
|
|
177
215
|
#log(fct, threshold) {
|
|
178
216
|
if (this.#segments.length > 0) {
|
|
179
217
|
if (this.#logLevel <= threshold) {
|
|
180
|
-
const
|
|
181
|
-
fct(...
|
|
218
|
+
const formattedSegments = formatSegments(this.#segments);
|
|
219
|
+
fct(...formattedSegments);
|
|
182
220
|
}
|
|
183
221
|
this.#resetSegments();
|
|
184
222
|
}
|
|
@@ -190,11 +228,12 @@ import logrocket from "logrocket";
|
|
|
190
228
|
}
|
|
191
229
|
/**
|
|
192
230
|
* @see {@link https://workleap.github.io/wl-logging}
|
|
193
|
-
*/ withText(text) {
|
|
231
|
+
*/ withText(text, options) {
|
|
194
232
|
if (text) {
|
|
195
233
|
this.#segments.push({
|
|
196
234
|
type: "text",
|
|
197
|
-
value: text
|
|
235
|
+
value: text,
|
|
236
|
+
options
|
|
198
237
|
});
|
|
199
238
|
}
|
|
200
239
|
return this;
|
|
@@ -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 } from \"@workleap/logging\";\nimport LogRocket from \"logrocket\";\n\ninterface Segment {\n type: \"text\" | \"object\" | \"error\" | \"line-change\";\n value: unknown;\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 values = segments.map(x => x.value);\n values.unshift(`(${this.#label})`);\n\n fct(...values);\n });\n }\n\n this.#resetSegments();\n }\n }\n\n /**\n * @see {@link https://workleap.github.io/wl-logging}\n */\n withText(text?: string) {\n if (text) {\n this.#segments.push({\n type: \"text\",\n value: text\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 values = this.#segments.map(x => x.value);\n\n fct(...values);\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) {\n if (text) {\n this.#segments.push({\n type: \"text\",\n value: text\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","LogRocketLoggerScope","label","logLevel","fct","threshold","segments","values","x","text","error","obj","log","options","dismiss","LogRocketLogger"],"mappings":";;;;;;;;AAA4H;AAC1F;AAUlC;;;CAGC,GACM,MAAME;IACA,SAAS,CAAW;IACpB,MAAM,CAAS;IAExB,SAAS,GAAc,EAAE,CAAC;IAC1B,YAAY,GAAiB,EAAE,CAAC;IAChC,SAAS,GAA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S,CAAC,IAAI,CAAC;YAChB,MAAM;YACN,OAAO;QACX;QAEA,OAAO,IAAI;IACf;IAEA;;;KAGC,GACD,MAAMC,GAAY,EAAE;QAChB,IAAIA,KAAK;YACL,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;gBAChB,MAAM;gBACN,OAAOA;YACX;QACJ;QAEA,IAAI,CAAC,IAAI,CAACZ,aAAa,EAAED,cAAc;IAC3C;IAEA;;;KAGC,GACD,YAAYa,GAAY,EAAE;QACtB,IAAIA,KAAK;YACL,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;gBAChB,MAAM;gBACN,OAAOA;YACX;QACJ;QAEA,IAAI,CAAC,IAAI,CAACZ,aAAa,EAAED,oBAAoB;IACjD;IAEA;;;KAGC,GACD,QAAQa,GAAY,EAAE;QAClB,IAAIA,KAAK;YACL,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;gBAChB,MAAM;gBACN,OAAOA;YACX;QACJ;QAEA,IAAI,CAAC,IAAI,CAACZ,cAAc,EAAED,gBAAgB;IAC9C;IAEA;;;KAGC,GACD,MAAMa,GAAY,EAAE;QAChB,IAAIA,KAAK;YACL,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;gBAChB,MAAM;gBACN,OAAOA;YACX;QACJ;QAEA,IAAI,CAAC,IAAI,CAACZ,eAAe,EAAED,cAAc;IAC7C;IAEA;;;KAGC,GACD,SAASa,GAAY,EAAE;QACnB,IAAIA,KAAK;YACL,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;gBAChB,MAAM;gBACN,OAAOA;YACX;QACJ;QAEA,IAAI,CAAC,IAAI,CAACZ,eAAe,EAAED,iBAAiB;IAChD;IAEA;;;KAGC,GACD,WAAWG,KAAa,EAAE;QACtB,OAAO,IAAID,qBAAqBC,OAAO,IAAI,CAAC,SAAS;IACzD;AACJ"}
|
|
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 } 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;IACvB;IAEA,IAAI,CAACE,GAAgB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AC,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,9 +1,61 @@
|
|
|
1
|
-
import { type Logger, type LoggerOptions, type LoggerScope, type LoggerScopeEndOptions, LogLevel } from "@workleap/logging";
|
|
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
4
|
interface Segment {
|
|
5
5
|
type: "text" | "object" | "error" | "line-change";
|
|
6
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
|
+
}
|
|
21
|
+
|
|
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 = "";
|
|
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();
|
|
50
|
+
|
|
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;
|
|
7
59
|
}
|
|
8
60
|
|
|
9
61
|
type LogFunction = (...rest: unknown[]) => void;
|
|
@@ -40,10 +92,10 @@ export class LogRocketLoggerScope implements LoggerScope {
|
|
|
40
92
|
const segments = this.#segments;
|
|
41
93
|
|
|
42
94
|
this.#pendingLogs.push(() => {
|
|
43
|
-
const
|
|
44
|
-
|
|
95
|
+
const formattedSegments = formatSegments(segments);
|
|
96
|
+
formattedSegments.unshift(`(${this.#label})`);
|
|
45
97
|
|
|
46
|
-
fct(...
|
|
98
|
+
fct(...formattedSegments);
|
|
47
99
|
});
|
|
48
100
|
}
|
|
49
101
|
|
|
@@ -54,11 +106,12 @@ export class LogRocketLoggerScope implements LoggerScope {
|
|
|
54
106
|
/**
|
|
55
107
|
* @see {@link https://workleap.github.io/wl-logging}
|
|
56
108
|
*/
|
|
57
|
-
withText(text?: string) {
|
|
109
|
+
withText(text?: string, options?: Omit<LogOptions, "style">) {
|
|
58
110
|
if (text) {
|
|
59
111
|
this.#segments.push({
|
|
60
112
|
type: "text",
|
|
61
|
-
value: text
|
|
113
|
+
value: text,
|
|
114
|
+
options
|
|
62
115
|
});
|
|
63
116
|
}
|
|
64
117
|
|
|
@@ -230,9 +283,9 @@ export class LogRocketLogger implements Logger {
|
|
|
230
283
|
#log(fct: LogFunction, threshold: LogLevel) {
|
|
231
284
|
if (this.#segments.length > 0) {
|
|
232
285
|
if (this.#logLevel <= threshold) {
|
|
233
|
-
const
|
|
286
|
+
const formattedSegments = formatSegments(this.#segments);
|
|
234
287
|
|
|
235
|
-
fct(...
|
|
288
|
+
fct(...formattedSegments);
|
|
236
289
|
}
|
|
237
290
|
|
|
238
291
|
this.#resetSegments();
|
|
@@ -249,11 +302,12 @@ export class LogRocketLogger implements Logger {
|
|
|
249
302
|
/**
|
|
250
303
|
* @see {@link https://workleap.github.io/wl-logging}
|
|
251
304
|
*/
|
|
252
|
-
withText(text?: string) {
|
|
305
|
+
withText(text?: string, options?: Omit<LogOptions, "style">) {
|
|
253
306
|
if (text) {
|
|
254
307
|
this.#segments.push({
|
|
255
308
|
type: "text",
|
|
256
|
-
value: text
|
|
309
|
+
value: text,
|
|
310
|
+
options
|
|
257
311
|
});
|
|
258
312
|
}
|
|
259
313
|
|