From: Chris Duncan Date: Sun, 20 Apr 2025 22:19:37 +0000 (-0700) Subject: Add debug logging for server process spawned by CLI. X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=998bccad6ca1f5628a9c71f05a2a7c5e2efde51f;p=nano-pow.git Add debug logging for server process spawned by CLI. --- diff --git a/src/bin/cli.ts b/src/bin/cli.ts index bf8720b..baac060 100755 --- a/src/bin/cli.ts +++ b/src/bin/cli.ts @@ -137,7 +137,10 @@ for (const stdinErr of stdinErrors) { log('Starting NanoPow CLI') const server = spawn(process.execPath, [new URL(import.meta.resolve('./server.js')).pathname], { stdio: ['pipe', 'pipe', 'pipe', 'ipc'] }) const port = await new Promise((resolve, reject): void => { - server.on('message', (msg: { type: string, port: number }): void => { + server.on('message', (msg: { type: string, port: number, text: string }): void => { + if (msg.type === 'console') { + log(msg.text) + } if (msg.type === 'listening') { if (msg.port != null) { log(`Server listening on port ${msg.port}`) diff --git a/src/bin/server.ts b/src/bin/server.ts index b208d22..dfce1f5 100755 --- a/src/bin/server.ts +++ b/src/bin/server.ts @@ -23,7 +23,9 @@ function log (...args: any[]): void { dateStyle: 'medium', timeStyle: 'medium' } - console.log(d.toLocaleString(Intl.DateTimeFormat().resolvedOptions().locale ?? 'en-US', opts), `NanoPow[${process.pid}]:`, args) + const text = `${d.toLocaleString(Intl.DateTimeFormat().resolvedOptions().locale ?? 'en-US', opts)} NanoPow[${process.pid}]: ${args}` + console.log(text) + process.send?.({ type: 'console', text }) } }