@arkyn/server 2.0.1-beta.3 → 2.0.1-beta.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/package.json +1 -1
- package/src/http/httpDebug.ts +8 -16
- package/src/services/getCaller.ts +40 -0
package/package.json
CHANGED
package/src/http/httpDebug.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { getCaller } from "../services/getCaller";
|
|
2
|
+
|
|
1
3
|
function httpDebug(name: string, body: any, cause?: any) {
|
|
2
4
|
const isDebugMode =
|
|
3
5
|
process.env.NODE_ENV === "development" ||
|
|
@@ -7,23 +9,13 @@ function httpDebug(name: string, body: any, cause?: any) {
|
|
|
7
9
|
const reset = "\x1b[0m";
|
|
8
10
|
const cyan = "\x1b[36m";
|
|
9
11
|
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
let callerLine = "Unknown caller";
|
|
14
|
-
for (const line of stackLines) {
|
|
15
|
-
if (
|
|
16
|
-
!line.includes("httpDebug") &&
|
|
17
|
-
!line.includes("BadGateway.<anonymous>")
|
|
18
|
-
) {
|
|
19
|
-
callerLine = line.trim();
|
|
20
|
-
break;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
12
|
+
const debugName = `${cyan}[ARKYN-DEBUG]${reset}`;
|
|
13
|
+
const { callerInfo, functionName } = getCaller();
|
|
23
14
|
|
|
24
|
-
console.log(`${
|
|
25
|
-
console.log(`${
|
|
26
|
-
console.log(`${
|
|
15
|
+
console.log(`${debugName} ${name} initialized`);
|
|
16
|
+
console.log(`${debugName} Caller Function: ${functionName}`);
|
|
17
|
+
console.log(`${debugName} Caller Location: ${callerInfo}`);
|
|
18
|
+
console.log(`${debugName} Body:`, body);
|
|
27
19
|
if (cause) console.log(`[ARKYN-DEBUG] Cause:`, cause);
|
|
28
20
|
}
|
|
29
21
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
|
|
3
|
+
function getCaller() {
|
|
4
|
+
// Diretório raiz do projeto
|
|
5
|
+
const projectRoot = process.cwd();
|
|
6
|
+
|
|
7
|
+
// Captura a stack trace
|
|
8
|
+
const error = new Error();
|
|
9
|
+
const stackLines = error.stack?.split("\n").map((line) => line.trim()) || [];
|
|
10
|
+
|
|
11
|
+
let callerInfo = "Unknown caller";
|
|
12
|
+
let functionName = "Unknown function";
|
|
13
|
+
|
|
14
|
+
for (const line of stackLines) {
|
|
15
|
+
if (
|
|
16
|
+
!line.includes("httpDebug") &&
|
|
17
|
+
!line.includes("BadGateway") &&
|
|
18
|
+
!line.includes("BadRequest")
|
|
19
|
+
) {
|
|
20
|
+
// Captura formatos diferentes de stack trace
|
|
21
|
+
const match = line.match(/at (.+?) \((.+?)\)/) || line.match(/at (.+)/);
|
|
22
|
+
if (match) {
|
|
23
|
+
functionName = match[1].split(" ")[0]; // Nome da função
|
|
24
|
+
let fullPath = match[2] || match[1]; // Caminho absoluto do arquivo
|
|
25
|
+
|
|
26
|
+
// Transforma caminho absoluto em relativo ao projeto
|
|
27
|
+
if (fullPath.startsWith(projectRoot)) {
|
|
28
|
+
fullPath = path.relative(projectRoot, fullPath);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
callerInfo = fullPath;
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return { functionName, callerInfo };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { getCaller };
|