testdriverai 7.3.39 → 7.3.40
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 +4 -0
- package/interfaces/logger.js +11 -49
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/interfaces/logger.js
CHANGED
|
@@ -11,43 +11,6 @@ class CustomTransport extends Transport {
|
|
|
11
11
|
this.level = opts.level || "info";
|
|
12
12
|
this.logStore = opts.logStore || []; // You could connect to a DB or API here
|
|
13
13
|
this.sandbox = null;
|
|
14
|
-
|
|
15
|
-
// Batching configuration to reduce websocket traffic
|
|
16
|
-
this.batchQueue = [];
|
|
17
|
-
this.batchTimeout = null;
|
|
18
|
-
this.BATCH_INTERVAL_MS = 100; // Flush every 100ms
|
|
19
|
-
this.MAX_BATCH_SIZE = 20; // Or when batch reaches 20 messages
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
_flushBatch() {
|
|
23
|
-
if (this.batchQueue.length === 0) return;
|
|
24
|
-
|
|
25
|
-
// Capture and clear the batch atomically to prevent duplicate sends
|
|
26
|
-
const batch = this.batchQueue;
|
|
27
|
-
this.batchQueue = [];
|
|
28
|
-
this.batchTimeout = null;
|
|
29
|
-
|
|
30
|
-
try {
|
|
31
|
-
if (!this.sandbox) {
|
|
32
|
-
this.sandbox = require("../agent/lib/sandbox");
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (this.sandbox && this.sandbox.instanceSocketConnected) {
|
|
36
|
-
// Send all batched messages as a single combined output
|
|
37
|
-
const combinedOutput = batch.join('\n');
|
|
38
|
-
this.sandbox.send({
|
|
39
|
-
type: "output",
|
|
40
|
-
output: Buffer.from(combinedOutput).toString("base64"),
|
|
41
|
-
}).catch((e) => {
|
|
42
|
-
// Re-queue failed messages for retry on next flush
|
|
43
|
-
console.error("Error sending log batch:", e);
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
} catch (e) {
|
|
47
|
-
// Re-queue on synchronous error as well
|
|
48
|
-
this.batchQueue = batch.concat(this.batchQueue);
|
|
49
|
-
console.error("Error flushing log batch:", e);
|
|
50
|
-
}
|
|
51
14
|
}
|
|
52
15
|
|
|
53
16
|
log(info, callback) {
|
|
@@ -61,18 +24,17 @@ class CustomTransport extends Transport {
|
|
|
61
24
|
return;
|
|
62
25
|
}
|
|
63
26
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
if (this.
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
this.batchTimeout = setTimeout(() => this._flushBatch(), this.BATCH_INTERVAL_MS);
|
|
27
|
+
if (!this.sandbox) {
|
|
28
|
+
this.sandbox = require("../agent/lib/sandbox");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (this.sandbox && this.sandbox.instanceSocketConnected) {
|
|
32
|
+
this.sandbox.send({
|
|
33
|
+
type: "output",
|
|
34
|
+
output: Buffer.from(message).toString("base64"),
|
|
35
|
+
}).catch((e) => {
|
|
36
|
+
console.error("Error sending log:", e);
|
|
37
|
+
});
|
|
76
38
|
}
|
|
77
39
|
} catch (e) {
|
|
78
40
|
console.error("Error in CustomTransport log method:", e);
|