| 1 | const fs = require('fs'); |
| 2 | const path = require('path'); |
| 3 | |
| 4 | const logDirPath = path.join(__dirname, '..', 'extensions', '.continue-debug', 'logs'); |
| 5 | const logFilePath = path.join(logDirPath, "prompt.log"); |
| 6 | |
| 7 | // Ensure the log directory exists |
| 8 | if (!fs.existsSync(logDirPath)) { |
| 9 | fs.mkdirSync(logDirPath, { recursive: true }); |
| 10 | console.log("Created log directory at " + logDirPath); |
| 11 | } |
| 12 | |
| 13 | // Create the log file if it doesn't exist |
| 14 | if (!fs.existsSync(logFilePath)) { |
| 15 | fs.writeFileSync(logFilePath, ''); // Create an empty file synchronously |
| 16 | console.log("Created empty log file at " + logFilePath); |
| 17 | } |
| 18 | |
| 19 | console.log("Watching logs at " + logFilePath); |
| 20 | |
| 21 | // Set up the file watcher |
| 22 | try { |
| 23 | fs.watch(logFilePath, () => { |
| 24 | try { |
| 25 | // console.clear(); |
| 26 | const stream = fs.createReadStream(logFilePath); |
| 27 | stream.pipe(process.stdout); |
| 28 | stream.on('error', (err) => { |
| 29 | console.error('Error reading log file:', err.message); |
| 30 | }); |
| 31 | } catch (err) { |
| 32 | console.error('Error while handling file change:', err.message); |
| 33 | } |
| 34 | }); |
| 35 | } catch (err) { |
| 36 | console.error('Error setting up file watcher:', err.message); |
| 37 | console.log('You may need to restart the script after the extension generates the first log entry.'); |
| 38 | } |