feat(logs): Improve logs streaming and backlog delivery; add CLI filters and ndjson output
This commit is contained in:
@@ -160,6 +160,55 @@ export class TspmIpcClient {
|
||||
await this.ipcClient.subscribe(topic, handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Request backlog logs as a stream from the daemon.
|
||||
* The actual stream will be delivered via the 'stream' event.
|
||||
*/
|
||||
public async requestLogsBacklogStream(
|
||||
processId: ProcessId | number | string,
|
||||
opts: { lines?: number; sinceTime?: number; types?: Array<'stdout' | 'stderr' | 'system'> } = {},
|
||||
): Promise<void> {
|
||||
if (!this.ipcClient || !this.isConnected) {
|
||||
throw new Error('Not connected to daemon');
|
||||
}
|
||||
const id = toProcessId(processId);
|
||||
await this.request('logs:subscribe' as any, {
|
||||
id,
|
||||
lines: opts.lines,
|
||||
sinceTime: opts.sinceTime,
|
||||
types: opts.types,
|
||||
} as any);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a handler for incoming streams (e.g., backlog logs)
|
||||
*/
|
||||
public onStream(
|
||||
handler: (info: any, readable: NodeJS.ReadableStream) => void,
|
||||
): void {
|
||||
if (!this.ipcClient) throw new Error('Not connected to daemon');
|
||||
// smartipc emits 'stream' with (info, readable)
|
||||
(this.ipcClient as any).on('stream', handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a temporary handler for backlog topic messages for a specific process
|
||||
*/
|
||||
public onBacklogTopic(
|
||||
processId: ProcessId | number | string,
|
||||
handler: (log: any) => void,
|
||||
): () => void {
|
||||
if (!this.ipcClient) throw new Error('Not connected to daemon');
|
||||
const id = toProcessId(processId);
|
||||
const topicType = `topic:logs.backlog.${id}`;
|
||||
(this.ipcClient as any).onMessage(topicType, handler);
|
||||
return () => {
|
||||
try {
|
||||
(this.ipcClient as any).messageHandlers?.delete?.(topicType);
|
||||
} catch {}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsubscribe from log updates for a specific process
|
||||
*/
|
||||
|
Reference in New Issue
Block a user