(params: {
backend: AppLogResult['backend'];
cmd: string;
args: string[];
stream: fs.WriteStream;
redactionPatterns: RegExp[];
pidPath?: string;
stopSignals?: NodeJS.Signals[];
})
| 300 | } |
| 301 | |
| 302 | function startAppleAppLogStream(params: { |
| 303 | backend: AppLogResult['backend']; |
| 304 | cmd: string; |
| 305 | args: string[]; |
| 306 | stream: fs.WriteStream; |
| 307 | redactionPatterns: RegExp[]; |
| 308 | pidPath?: string; |
| 309 | stopSignals?: NodeJS.Signals[]; |
| 310 | }): AppLogResult { |
| 311 | let state: AppLogState = 'active'; |
| 312 | const background = runCmdBackground(params.cmd, params.args, { |
| 313 | allowFailure: true, |
| 314 | captureOutput: false, |
| 315 | }); |
| 316 | void background.wait.catch(() => {}); |
| 317 | const child = background.child; |
| 318 | const writer = createLineWriter(params.stream, { redactionPatterns: params.redactionPatterns }); |
| 319 | if (typeof child.pid === 'number') { |
| 320 | writePidFile(params.pidPath, child.pid); |
| 321 | } |
| 322 | const wait = attachChildToStream(child, params.stream, { |
| 323 | endStreamOnClose: true, |
| 324 | writer, |
| 325 | }).then( |
| 326 | (result) => { |
| 327 | state = result.exitCode === 0 ? 'ended' : 'failed'; |
| 328 | clearPidFile(params.pidPath); |
| 329 | return result; |
| 330 | }, |
| 331 | (error: unknown) => { |
| 332 | state = 'failed'; |
| 333 | clearPidFile(params.pidPath); |
| 334 | throw error; |
| 335 | }, |
| 336 | ); |
| 337 | return { |
| 338 | backend: params.backend, |
| 339 | getState: () => state, |
| 340 | startedAt: Date.now(), |
| 341 | wait, |
| 342 | stop: async () => { |
| 343 | for (const signal of params.stopSignals ?? ['SIGINT', 'SIGKILL']) { |
| 344 | child.kill(signal); |
| 345 | await waitForChildExit(wait); |
| 346 | } |
| 347 | clearPidFile(params.pidPath); |
| 348 | }, |
| 349 | }; |
| 350 | } |
no test coverage detected