Skip to content

Commit 8065f45

Browse files
add execution logs in file
1 parent 184dcb5 commit 8065f45

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/tasks/exec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import chalk from 'chalk'
44
import spawn from 'cross-spawn'
55
import { updateLogContext } from '../lib/logger.js'
66
import { startPolling, startSSEListener } from '../lib/utils.js'
7+
import fs from 'fs'
8+
import path from 'path'
79

810
export default (ctx: Context): ListrTask<Context, ListrRendererFactory, ListrRendererFactory> => {
911
return {
@@ -38,6 +40,25 @@ export default (ctx: Context): ListrTask<Context, ListrRendererFactory, ListrRen
3840
})
3941
childProcess.stdout?.pipe(output);
4042
childProcess.stderr?.pipe(output);
43+
} else {
44+
// Write logs to file when skipping terminal output
45+
const logFileName = `execution-logs.log`;
46+
const logFilePath = path.join(process.cwd(), logFileName);
47+
const logStream = fs.createWriteStream(logFilePath, { flags: 'a' });
48+
49+
task.output = chalk.gray(`Execution logs being written to: ${logFileName}`);
50+
51+
childProcess.stdout?.on('data', (data) => {
52+
logStream.write(data);
53+
});
54+
55+
childProcess.stderr?.on('data', (data) => {
56+
logStream.write(data);
57+
});
58+
59+
childProcess.on('close', () => {
60+
logStream.end();
61+
});
4162
}
4263

4364
childProcess.on('error', (error) => {

0 commit comments

Comments
 (0)