From 44e439631ee1b9eb8a4a7726b5bdcffcec9199a2 Mon Sep 17 00:00:00 2001 From: redshift <213178690+1ftredsh@users.noreply.github.com> Date: Mon, 23 Mar 2026 13:24:19 +0000 Subject: [PATCH] debug logs from sdk are now shown in routstrd logs --- src/daemon/http/index.ts | 1 - src/start-daemon.ts | 28 ++++++++++++++++++---------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/daemon/http/index.ts b/src/daemon/http/index.ts index 56c30e8..d233a11 100644 --- a/src/daemon/http/index.ts +++ b/src/daemon/http/index.ts @@ -445,7 +445,6 @@ export function createDaemonRequestHandler(deps: { res.on("finish", () => { if (capturedUsage) { const usageRequestId = capturedResponseId || requestId || "unknown"; - logger.log(req); usageTracker.append({ id: usageRequestId === "unknown" diff --git a/src/start-daemon.ts b/src/start-daemon.ts index fc45ee6..be23240 100644 --- a/src/start-daemon.ts +++ b/src/start-daemon.ts @@ -1,5 +1,7 @@ import { LOG_FILE } from "./utils/config"; import { logger } from "./utils/logger"; +import { existsSync, mkdirSync } from "fs"; +import { dirname, join } from "path"; export async function startDaemon( options: { port?: string; provider?: string } = {}, @@ -31,17 +33,23 @@ export async function startDaemon( args.push("--provider", options.provider); } - const logFile = Bun.file(LOG_FILE); + // Ensure log directory exists + const logDir = dirname(LOG_FILE); + if (!existsSync(logDir)) { + mkdirSync(logDir, { recursive: true }); + } - const proc = Bun.spawn( - ["bun", "run", `${import.meta.dir}/daemon/index.ts`, ...args], - { - stdout: logFile, - stderr: logFile, - stdin: "ignore", - detached: true, - }, - ); + // Use shell redirection to append stdout/stderr to log file + // Bun.file() overwrites, so we need shell >> for appending + const daemonScript = `${import.meta.dir}/daemon/index.ts`; + const shellCmd = `bun run "${daemonScript}" ${args.map(a => `'${a}'`).join(" ")} >> "${LOG_FILE}" 2>&1`; + + const proc = Bun.spawn(["sh", "-c", shellCmd], { + stdout: "inherit", + stderr: "inherit", + stdin: "ignore", + detached: true, + }); proc.unref();