From d1887a6964c6a223d5c85733f4cfbcf0aa4b759d Mon Sep 17 00:00:00 2001 From: yaroslav8765 Date: Wed, 25 Mar 2026 17:42:22 +0200 Subject: [PATCH] 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(() => {}); }