fix(cli): Refactor logs command to use child_process spawn for real-time log tailing

This commit is contained in:
2025-03-25 09:20:55 +00:00
parent 9bfb948e5c
commit 8431ef91a8
4 changed files with 41 additions and 3 deletions

View File

@@ -131,8 +131,24 @@ export class NupstCli {
*/
private async logs(): Promise<void> {
try {
const logs = execSync('journalctl -u nupst.service -n 50 -f').toString();
console.log(logs);
// Use exec with spawn to properly follow logs in real-time
const { spawn } = await import('child_process');
console.log('Tailing nupst service logs (Ctrl+C to exit)...\n');
const journalctl = spawn('journalctl', ['-u', 'nupst.service', '-n', '50', '-f'], {
stdio: ['ignore', 'inherit', 'inherit']
});
// Forward signals to child process
process.on('SIGINT', () => {
journalctl.kill('SIGINT');
process.exit(0);
});
// Wait for process to exit
await new Promise<void>((resolve) => {
journalctl.on('exit', () => resolve());
});
} catch (error) {
console.error('Failed to retrieve logs:', error);
process.exit(1);