mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-04 09:13:08 +00:00
refactor: replace logger with console statements in subprocess management
- Removed the centralized logging system in favor of direct console.log and console.error statements for subprocess management. - Updated logging messages to include context for subprocess actions, such as spawning commands, handling errors, and process completion. - This change simplifies the logging approach in subprocess handling, making it easier to track subprocess activities during development.
This commit is contained in:
@@ -4,9 +4,6 @@
|
|||||||
|
|
||||||
import { spawn, type ChildProcess } from 'child_process';
|
import { spawn, type ChildProcess } from 'child_process';
|
||||||
import readline from 'readline';
|
import readline from 'readline';
|
||||||
import { createLogger } from '@automaker/utils/logger';
|
|
||||||
|
|
||||||
const logger = createLogger('SubprocessManager');
|
|
||||||
|
|
||||||
export interface SubprocessOptions {
|
export interface SubprocessOptions {
|
||||||
command: string;
|
command: string;
|
||||||
@@ -41,10 +38,10 @@ export async function* spawnJSONLProcess(options: SubprocessOptions): AsyncGener
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Log command without stdin data (which may be large/sensitive)
|
// Log command without stdin data (which may be large/sensitive)
|
||||||
logger.info(`Spawning: ${command} ${args.join(' ')}`);
|
console.log(`[SubprocessManager] Spawning: ${command} ${args.join(' ')}`);
|
||||||
logger.info(`Working directory: ${cwd}`);
|
console.log(`[SubprocessManager] Working directory: ${cwd}`);
|
||||||
if (stdinData) {
|
if (stdinData) {
|
||||||
logger.info(`Passing ${stdinData.length} bytes via stdin`);
|
console.log(`[SubprocessManager] Passing ${stdinData.length} bytes via stdin`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const childProcess: ChildProcess = spawn(command, args, {
|
const childProcess: ChildProcess = spawn(command, args, {
|
||||||
@@ -69,7 +66,7 @@ export async function* spawnJSONLProcess(options: SubprocessOptions): AsyncGener
|
|||||||
childProcess.stderr.on('data', (data: Buffer) => {
|
childProcess.stderr.on('data', (data: Buffer) => {
|
||||||
const text = data.toString();
|
const text = data.toString();
|
||||||
stderrOutput += text;
|
stderrOutput += text;
|
||||||
logger.warn(`stderr: ${text}`);
|
console.warn(`[SubprocessManager] stderr: ${text}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,7 +79,7 @@ export async function* spawnJSONLProcess(options: SubprocessOptions): AsyncGener
|
|||||||
timeoutHandle = setTimeout(() => {
|
timeoutHandle = setTimeout(() => {
|
||||||
const elapsed = Date.now() - lastOutputTime;
|
const elapsed = Date.now() - lastOutputTime;
|
||||||
if (elapsed >= timeout) {
|
if (elapsed >= timeout) {
|
||||||
logger.error(`Process timeout: no output for ${timeout}ms`);
|
console.error(`[SubprocessManager] Process timeout: no output for ${timeout}ms`);
|
||||||
childProcess.kill('SIGTERM');
|
childProcess.kill('SIGTERM');
|
||||||
}
|
}
|
||||||
}, timeout);
|
}, timeout);
|
||||||
@@ -93,7 +90,7 @@ export async function* spawnJSONLProcess(options: SubprocessOptions): AsyncGener
|
|||||||
// Setup abort handling
|
// Setup abort handling
|
||||||
if (abortController) {
|
if (abortController) {
|
||||||
abortController.signal.addEventListener('abort', () => {
|
abortController.signal.addEventListener('abort', () => {
|
||||||
logger.info('Abort signal received, killing process');
|
console.log('[SubprocessManager] Abort signal received, killing process');
|
||||||
if (timeoutHandle) {
|
if (timeoutHandle) {
|
||||||
clearTimeout(timeoutHandle);
|
clearTimeout(timeoutHandle);
|
||||||
}
|
}
|
||||||
@@ -118,7 +115,7 @@ export async function* spawnJSONLProcess(options: SubprocessOptions): AsyncGener
|
|||||||
const parsed = JSON.parse(line);
|
const parsed = JSON.parse(line);
|
||||||
yield parsed;
|
yield parsed;
|
||||||
} catch (parseError) {
|
} catch (parseError) {
|
||||||
logger.error(`Failed to parse JSONL line: ${line}`, parseError);
|
console.error(`[SubprocessManager] Failed to parse JSONL line: ${line}`, parseError);
|
||||||
// Yield error but continue processing
|
// Yield error but continue processing
|
||||||
yield {
|
yield {
|
||||||
type: 'error',
|
type: 'error',
|
||||||
@@ -127,7 +124,7 @@ export async function* spawnJSONLProcess(options: SubprocessOptions): AsyncGener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('Error reading stdout:', error);
|
console.error('[SubprocessManager] Error reading stdout:', error);
|
||||||
throw error;
|
throw error;
|
||||||
} finally {
|
} finally {
|
||||||
if (timeoutHandle) {
|
if (timeoutHandle) {
|
||||||
@@ -139,12 +136,12 @@ export async function* spawnJSONLProcess(options: SubprocessOptions): AsyncGener
|
|||||||
// Wait for process to exit
|
// Wait for process to exit
|
||||||
const exitCode = await new Promise<number | null>((resolve) => {
|
const exitCode = await new Promise<number | null>((resolve) => {
|
||||||
childProcess.on('exit', (code) => {
|
childProcess.on('exit', (code) => {
|
||||||
logger.info(`Process exited with code: ${code}`);
|
console.log(`[SubprocessManager] Process exited with code: ${code}`);
|
||||||
resolve(code);
|
resolve(code);
|
||||||
});
|
});
|
||||||
|
|
||||||
childProcess.on('error', (error) => {
|
childProcess.on('error', (error) => {
|
||||||
logger.error('Process error:', error);
|
console.error('[SubprocessManager] Process error:', error);
|
||||||
resolve(null);
|
resolve(null);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -152,7 +149,7 @@ export async function* spawnJSONLProcess(options: SubprocessOptions): AsyncGener
|
|||||||
// Handle non-zero exit codes
|
// Handle non-zero exit codes
|
||||||
if (exitCode !== 0 && exitCode !== null) {
|
if (exitCode !== 0 && exitCode !== null) {
|
||||||
const errorMessage = stderrOutput || `Process exited with code ${exitCode}`;
|
const errorMessage = stderrOutput || `Process exited with code ${exitCode}`;
|
||||||
logger.error(`Process failed: ${errorMessage}`);
|
console.error(`[SubprocessManager] Process failed: ${errorMessage}`);
|
||||||
yield {
|
yield {
|
||||||
type: 'error',
|
type: 'error',
|
||||||
error: errorMessage,
|
error: errorMessage,
|
||||||
@@ -161,7 +158,7 @@ export async function* spawnJSONLProcess(options: SubprocessOptions): AsyncGener
|
|||||||
|
|
||||||
// Process completed successfully
|
// Process completed successfully
|
||||||
if (exitCode === 0 && !stderrOutput) {
|
if (exitCode === 0 && !stderrOutput) {
|
||||||
logger.info('Process completed successfully');
|
console.log('[SubprocessManager] Process completed successfully');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user