feat(logging): add newline to regex.ready and log output to /tmp/regex.log
This commit is contained in:
parent
94c126029d
commit
700a868a3a
|
@ -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]);
|
||||
|
|
|
@ -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 = [];
|
||||
|
|
Loading…
Reference in New Issue