Elffuss BraidHub

kikocis/continue public

a8f7feae0254 · 1.2 KiBRawPermalink
1const fs = require('fs');
2const path = require('path');
3
4const logDirPath = path.join(__dirname, '..', 'extensions', '.continue-debug', 'logs');
5const logFilePath = path.join(logDirPath, "prompt.log");
6
7// Ensure the log directory exists
8if (!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
14if (!fs.existsSync(logFilePath)) {
15 fs.writeFileSync(logFilePath, ''); // Create an empty file synchronously
16 console.log("Created empty log file at " + logFilePath);
17}
18
19console.log("Watching logs at " + logFilePath);
20
21// Set up the file watcher
22try {
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}