MCPcopy Create free account
hub / github.com/Gan-Xing/CodexBridge / followLogFiles

Function followLogFiles

packages/codex-native-api/src/daemon_manager.ts:1072–1108  ·  view source on GitHub ↗
(filePaths: string[])

Source from the content-addressed store, hash-verified

1070}
1071
1072async function followLogFiles(filePaths: string[]): Promise<void> {
1073 const positions = new Map<string, number>();
1074 for (const filePath of filePaths) {
1075 try {
1076 const stats = await fsp.stat(filePath);
1077 positions.set(filePath, stats.size);
1078 } catch {
1079 positions.set(filePath, 0);
1080 }
1081 }
1082 await new Promise<void>(() => {
1083 const timer = setInterval(async () => {
1084 for (const filePath of filePaths) {
1085 try {
1086 const stats = await fsp.stat(filePath);
1087 const previousSize = positions.get(filePath) ?? 0;
1088 if (stats.size <= previousSize) {
1089 continue;
1090 }
1091 const handle = await fsp.open(filePath, 'r');
1092 try {
1093 const buffer = Buffer.alloc(stats.size - previousSize);
1094 await handle.read(buffer, 0, buffer.length, previousSize);
1095 process.stdout.write(buffer.toString('utf8'));
1096 positions.set(filePath, stats.size);
1097 } finally {
1098 await handle.close();
1099 }
1100 } catch {
1101 // Ignore transient read errors while following logs.
1102 }
1103 }
1104 }, 1000);
1105 process.on('SIGINT', () => clearInterval(timer));
1106 process.on('SIGTERM', () => clearInterval(timer));
1107 });
1108}
1109
1110function buildServicePathEnv(platform: NodeJS.Platform, currentPath: string | undefined, nodeBin: string): string {
1111 const parts = new Set<string>();

Callers 1

logsDaemonFunction · 0.85

Calls 3

readMethod · 0.80
writeMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected