From b7836fcec216d7770807ef868d7db5a7383220de Mon Sep 17 00:00:00 2001 From: Matthew Jackson Date: Fri, 6 Mar 2026 11:59:27 -0800 Subject: [PATCH] Tee applier stdout/stderr to data/applier.log Writes all console output to a log file from inside the process so logs are always available regardless of how the process is launched. Fixes invisible output when claw redirects stdout to a file that gets overwritten by a second lock-blocked attempt. Co-Authored-By: Claude Opus 4.6 --- job_applier.mjs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/job_applier.mjs b/job_applier.mjs index 41b07d1..46d6c4f 100644 --- a/job_applier.mjs +++ b/job_applier.mjs @@ -6,12 +6,19 @@ loadEnv(); // load .env before anything else * Reads jobs queue and applies using the appropriate handler per apply_type * Run via cron or manually: node job_applier.mjs [--preview] */ -import { existsSync, writeFileSync } from 'fs'; +import { existsSync, writeFileSync, createWriteStream } from 'fs'; import { dirname, resolve } from 'path'; import { fileURLToPath } from 'url'; const __dir = dirname(fileURLToPath(import.meta.url)); +// Tee all output to a log file so it's always available regardless of how the process is launched +const logStream = createWriteStream(resolve(__dir, 'data/applier.log'), { flags: 'w' }); +const origStdoutWrite = process.stdout.write.bind(process.stdout); +const origStderrWrite = process.stderr.write.bind(process.stderr); +process.stdout.write = (chunk, ...args) => { logStream.write(chunk); return origStdoutWrite(chunk, ...args); }; +process.stderr.write = (chunk, ...args) => { logStream.write(chunk); return origStderrWrite(chunk, ...args); }; + import { getJobsByStatus, updateJobStatus, appendLog, loadConfig, isAlreadyApplied } from './lib/queue.mjs'; import { acquireLock } from './lib/lock.mjs'; import { createBrowser } from './lib/browser.mjs';