tarsec 0.1.5 → 0.1.7
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/dist/trace.d.ts +3 -0
- package/dist/trace.js +33 -0
- package/package.json +1 -1
package/dist/trace.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { ParserResult, Parser, PlainObject, CaptureParser } from "./types.js";
|
|
2
|
+
export declare function setTraceHost(host: string): void;
|
|
3
|
+
export declare function getTraceHost(): string;
|
|
4
|
+
export declare function setTraceId(id: string): void;
|
|
2
5
|
/**
|
|
3
6
|
* This function is used internally by the `trace` function to create the string for each step.
|
|
4
7
|
* @param name - debug name for parser
|
package/dist/trace.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { escape, round, shorten } from "./utils.js";
|
|
2
2
|
import process from "process";
|
|
3
|
+
import { execSync } from "child_process";
|
|
3
4
|
const isNode = typeof process !== "undefined" &&
|
|
4
5
|
process.versions != null &&
|
|
5
6
|
process.versions.node != null;
|
|
@@ -11,6 +12,17 @@ let debugFlag = isNode ? !!process.env.DEBUG : false;
|
|
|
11
12
|
let stepCount = 0;
|
|
12
13
|
let stepLimit = -1;
|
|
13
14
|
let debugMessages = [];
|
|
15
|
+
let traceHost = "";
|
|
16
|
+
let traceId = "1";
|
|
17
|
+
export function setTraceHost(host) {
|
|
18
|
+
traceHost = host;
|
|
19
|
+
}
|
|
20
|
+
export function getTraceHost() {
|
|
21
|
+
return traceHost;
|
|
22
|
+
}
|
|
23
|
+
export function setTraceId(id) {
|
|
24
|
+
traceId = id;
|
|
25
|
+
}
|
|
14
26
|
/**
|
|
15
27
|
* This function is used internally by the `trace` function to create the string for each step.
|
|
16
28
|
* @param name - debug name for parser
|
|
@@ -30,6 +42,16 @@ export function trace(name, parser) {
|
|
|
30
42
|
return (input) => {
|
|
31
43
|
if (debugFlag) {
|
|
32
44
|
console.log(" ".repeat(level) + `🔍 ${name} -- input: ${shorten(escape(input))}`);
|
|
45
|
+
if (traceHost && traceHost.length > 0) {
|
|
46
|
+
const json = JSON.stringify({
|
|
47
|
+
traceId,
|
|
48
|
+
name,
|
|
49
|
+
type: "start",
|
|
50
|
+
level,
|
|
51
|
+
timestamp: Date.now(),
|
|
52
|
+
});
|
|
53
|
+
execSync(`curl -s -X POST -H "Content-Type: application/json" -d '${json}' ${traceHost}/api/logs`);
|
|
54
|
+
}
|
|
33
55
|
let result;
|
|
34
56
|
const time = parserTime(() => {
|
|
35
57
|
level += STEP;
|
|
@@ -46,6 +68,17 @@ export function trace(name, parser) {
|
|
|
46
68
|
console.log(" ".repeat(level) +
|
|
47
69
|
`⭐ ${name} -- captures: ${JSON.stringify(result.captures)}`);
|
|
48
70
|
}
|
|
71
|
+
if (traceHost && traceHost.length > 0) {
|
|
72
|
+
const json = JSON.stringify({
|
|
73
|
+
traceId,
|
|
74
|
+
name,
|
|
75
|
+
type: "end",
|
|
76
|
+
level,
|
|
77
|
+
timestamp: Date.now(),
|
|
78
|
+
result,
|
|
79
|
+
});
|
|
80
|
+
execSync(`curl -s -X POST -H "Content-Type: application/json" -d '${json}' ${traceHost}/api/logs`);
|
|
81
|
+
}
|
|
49
82
|
return result;
|
|
50
83
|
}
|
|
51
84
|
else {
|