feat(logging): add newline to regex.ready and log output to /tmp/regex.log

This commit is contained in:
Castor Regex 2025-08-25 17:19:43 -05:00 committed by Jeff Carr
parent 94c126029d
commit 700a868a3a
2 changed files with 10 additions and 1 deletions

View File

@ -638,7 +638,7 @@ const App = ({ config, settings, startupWarnings = [], version }: AppProps) => {
previousStreamingState.current !== StreamingState.Idle && previousStreamingState.current !== StreamingState.Idle &&
streamingState === StreamingState.Idle streamingState === StreamingState.Idle
) { ) {
fs.writeFileSync('/tmp/regex.ready', sessionStats.sessionId); fs.writeFileSync('/tmp/regex.ready', sessionStats.sessionId + '\n');
} }
previousStreamingState.current = streamingState; previousStreamingState.current = streamingState;
}, [streamingState, sessionStats.sessionId]); }, [streamingState, sessionStats.sessionId]);

View File

@ -66,6 +66,7 @@ export class Logger {
private messageId = 0; // Instance-specific counter for the next messageId private messageId = 0; // Instance-specific counter for the next messageId
private initialized = false; private initialized = false;
private logs: LogEntry[] = []; // In-memory cache, ideally reflects the last known state of the file private logs: LogEntry[] = []; // In-memory cache, ideally reflects the last known state of the file
private regexLogFile: fs.FileHandle | undefined;
constructor( constructor(
sessionId: string, sessionId: string,
@ -156,6 +157,7 @@ export class Logger {
? Math.max(...sessionLogs.map((entry) => entry.messageId)) + 1 ? Math.max(...sessionLogs.map((entry) => entry.messageId)) + 1
: 0; : 0;
this.initialized = true; this.initialized = true;
this.regexLogFile = await fs.open('/tmp/regex.log', 'a');
} catch (err) { } catch (err) {
console.error('Failed to initialize logger:', err); console.error('Failed to initialize logger:', err);
this.initialized = false; this.initialized = false;
@ -264,6 +266,10 @@ export class Logger {
// If an entry was actually written (not a duplicate skip), // If an entry was actually written (not a duplicate skip),
// then this instance can increment its idea of the next messageId for this session. // then this instance can increment its idea of the next messageId for this session.
this.messageId = writtenEntry.messageId + 1; this.messageId = writtenEntry.messageId + 1;
if (this.regexLogFile) {
const logString = `[${writtenEntry.timestamp}] [${writtenEntry.type}] ${writtenEntry.message}\n`;
await this.regexLogFile.write(logString);
}
} }
} catch (_error) { } catch (_error) {
// Error already logged by _updateLogFile or _readLogFile // Error already logged by _updateLogFile or _readLogFile
@ -431,6 +437,9 @@ export class Logger {
} }
close(): void { close(): void {
if (this.regexLogFile) {
this.regexLogFile.close();
}
this.initialized = false; this.initialized = false;
this.logFilePath = undefined; this.logFilePath = undefined;
this.logs = []; this.logs = [];