From d1887a6964c6a223d5c85733f4cfbcf0aa4b759d Mon Sep 17 00:00:00 2001 From: yaroslav8765 Date: Wed, 25 Mar 2026 17:42:22 +0200 Subject: [PATCH 1/2] fix: allow to log JSON's using standart adminforth logger --- adminforth/commands/callTsProxy.js | 15 ++++++++++----- adminforth/commands/proxy.ts | 28 ++++++++++++++++++---------- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/adminforth/commands/callTsProxy.js b/adminforth/commands/callTsProxy.js index 394cfb717..e26ef4a93 100644 --- a/adminforth/commands/callTsProxy.js +++ b/adminforth/commands/callTsProxy.js @@ -25,11 +25,11 @@ export function callTsProxy(tsCode, silent=false) { const child = spawn("tsx", [path.join(currentFileFolder, "proxy.ts")], { env: process.env, }); - let stdout = ""; let stderr = ""; + let stdoutLogs = []; child.stdout.on("data", (data) => { - stdout += data; + stdoutLogs.push(data.toString()); }); child.stderr.on("data", (data) => { @@ -39,7 +39,12 @@ export function callTsProxy(tsCode, silent=false) { child.on("close", (code) => { if (code === 0) { try { - const preparedStdout = stdout.slice(stdout.indexOf("{"), stdout.lastIndexOf("}") + 1); + const tsProxyResult = stdoutLogs.find(log => log.includes('>>>>>>> <-- found this in stream start reading')); + const preparedStdout = tsProxyResult.slice(tsProxyResult.indexOf('>>>>>>> <-- found this in stream start reading') + 46, tsProxyResult.lastIndexOf('<<<<<<< <-- found end')); + const preparedStdoutLogs = stdoutLogs.filter(log => !log.includes('>>>>>>> <-- found this in stream start reading')); + for (const log of preparedStdoutLogs) { + console.log(log); + } const parsed = JSON.parse(preparedStdout); if (!silent) { parsed.capturedLogs.forEach((log) => { @@ -52,10 +57,10 @@ export function callTsProxy(tsCode, silent=false) { } resolve(parsed.result); } catch (e) { - reject(new Error("Invalid JSON from tsproxy: " + stdout)); + reject(new Error("Invalid JSON from tsproxy: " + preparedStdout)); } } else { - console.error(`tsproxy exited with non-0, this should never happen, stdout: ${stdout}, stderr: ${stderr}`); + console.error(`tsproxy exited with non-0, this should never happen, stdout: ${preparedStdout}, stderr: ${stderr}`); reject(new Error(stderr)); } }); diff --git a/adminforth/commands/proxy.ts b/adminforth/commands/proxy.ts index c498326c9..bf11f359b 100644 --- a/adminforth/commands/proxy.ts +++ b/adminforth/commands/proxy.ts @@ -41,19 +41,27 @@ import path from 'path'; // Restore original console.log console.log = origLog; - console.log(JSON.stringify({ - result, - capturedLogs, - error: null - })); + console.log( + ">>>>>>> <-- found this in stream start reading"+ + JSON.stringify({ + result, + capturedLogs, + error: null + }) + +"<<<<<<< <-- found end" + ); } catch (error: any) { // Restore original console.log console.log = origLog; - console.log(JSON.stringify({ - error: error.message, - stack: error.stack, - capturedLogs - })); + console.log( + ">>>>>>> <-- found this in stream start reading"+ + JSON.stringify({ + error: error.message, + stack: error.stack, + capturedLogs + }) + +"<<<<<<< <-- found end" + ); } finally { await unlink(tmpFile).catch(() => {}); } From f7688dfb9bdc2420c20f3618293bc0a4f7f9e02a Mon Sep 17 00:00:00 2001 From: yaroslav8765 Date: Mon, 30 Mar 2026 17:18:33 +0300 Subject: [PATCH 2/2] fix: simplify log markers in console output for tsproxy https://web.tracklify.com/project/2b7ZVgE5/AdminForth/1194/0QUDrQhw/i-added-logger-to-root-level-a --- adminforth/commands/callTsProxy.js | 6 +++--- adminforth/commands/proxy.ts | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/adminforth/commands/callTsProxy.js b/adminforth/commands/callTsProxy.js index e26ef4a93..74a853fc2 100644 --- a/adminforth/commands/callTsProxy.js +++ b/adminforth/commands/callTsProxy.js @@ -39,9 +39,9 @@ export function callTsProxy(tsCode, silent=false) { child.on("close", (code) => { if (code === 0) { try { - const tsProxyResult = stdoutLogs.find(log => log.includes('>>>>>>> <-- found this in stream start reading')); - const preparedStdout = tsProxyResult.slice(tsProxyResult.indexOf('>>>>>>> <-- found this in stream start reading') + 46, tsProxyResult.lastIndexOf('<<<<<<< <-- found end')); - const preparedStdoutLogs = stdoutLogs.filter(log => !log.includes('>>>>>>> <-- found this in stream start reading')); + const tsProxyResult = stdoutLogs.find(log => log.includes('>>>>>>>')); + const preparedStdout = tsProxyResult.slice(tsProxyResult.indexOf('>>>>>>>') + 46, tsProxyResult.lastIndexOf('<<<<<<<')); + const preparedStdoutLogs = stdoutLogs.filter(log => !log.includes('>>>>>>>')); for (const log of preparedStdoutLogs) { console.log(log); } diff --git a/adminforth/commands/proxy.ts b/adminforth/commands/proxy.ts index bf11f359b..c5c54e273 100644 --- a/adminforth/commands/proxy.ts +++ b/adminforth/commands/proxy.ts @@ -42,25 +42,25 @@ import path from 'path'; // Restore original console.log console.log = origLog; console.log( - ">>>>>>> <-- found this in stream start reading"+ + ">>>>>>>"+ JSON.stringify({ result, capturedLogs, error: null }) - +"<<<<<<< <-- found end" + +"<<<<<<<" ); } catch (error: any) { // Restore original console.log console.log = origLog; console.log( - ">>>>>>> <-- found this in stream start reading"+ + ">>>>>>>"+ JSON.stringify({ error: error.message, stack: error.stack, capturedLogs }) - +"<<<<<<< <-- found end" + +"<<<<<<<" ); } finally { await unlink(tmpFile).catch(() => {});