From 700a868a3aa41f07f7c314310c177c9d8d2b9b5d Mon Sep 17 00:00:00 2001 From: Castor Regex Date: Mon, 25 Aug 2025 17:19:43 -0500 Subject: [PATCH] feat(logging): add newline to regex.ready and log output to /tmp/regex.log --- packages/cli/src/ui/App.tsx | 2 +- packages/core/src/core/logger.ts | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/ui/App.tsx b/packages/cli/src/ui/App.tsx index 34edd2fd..ebd24e97 100644 --- a/packages/cli/src/ui/App.tsx +++ b/packages/cli/src/ui/App.tsx @@ -638,7 +638,7 @@ const App = ({ config, settings, startupWarnings = [], version }: AppProps) => { previousStreamingState.current !== StreamingState.Idle && streamingState === StreamingState.Idle ) { - fs.writeFileSync('/tmp/regex.ready', sessionStats.sessionId); + fs.writeFileSync('/tmp/regex.ready', sessionStats.sessionId + '\n'); } previousStreamingState.current = streamingState; }, [streamingState, sessionStats.sessionId]); diff --git a/packages/core/src/core/logger.ts b/packages/core/src/core/logger.ts index 562b14bf..76a2bfbe 100644 --- a/packages/core/src/core/logger.ts +++ b/packages/core/src/core/logger.ts @@ -66,6 +66,7 @@ export class Logger { private messageId = 0; // Instance-specific counter for the next messageId private initialized = false; private logs: LogEntry[] = []; // In-memory cache, ideally reflects the last known state of the file + private regexLogFile: fs.FileHandle | undefined; constructor( sessionId: string, @@ -156,6 +157,7 @@ export class Logger { ? Math.max(...sessionLogs.map((entry) => entry.messageId)) + 1 : 0; this.initialized = true; + this.regexLogFile = await fs.open('/tmp/regex.log', 'a'); } catch (err) { console.error('Failed to initialize logger:', err); this.initialized = false; @@ -264,6 +266,10 @@ export class Logger { // If an entry was actually written (not a duplicate skip), // then this instance can increment its idea of the next messageId for this session. this.messageId = writtenEntry.messageId + 1; + if (this.regexLogFile) { + const logString = `[${writtenEntry.timestamp}] [${writtenEntry.type}] ${writtenEntry.message}\n`; + await this.regexLogFile.write(logString); + } } } catch (_error) { // Error already logged by _updateLogFile or _readLogFile @@ -431,6 +437,9 @@ export class Logger { } close(): void { + if (this.regexLogFile) { + this.regexLogFile.close(); + } this.initialized = false; this.logFilePath = undefined; this.logs = [];