From a40e4b863bb359cec7e58355841de453ff7cd304 Mon Sep 17 00:00:00 2001 From: Zaid Abdulla Date: Tue, 5 Jan 2021 12:09:12 -0800 Subject: [PATCH] Pipe stdout/stderr from ext to process log --- build/build.ts | 1 + lib/extensions.ts | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/build/build.ts b/build/build.ts index 7c73a30..3d347f9 100644 --- a/build/build.ts +++ b/build/build.ts @@ -63,6 +63,7 @@ const externals = [ "child_process", "dgram", "url", + "readline", "iconv-lite", "koa", "koa-router", diff --git a/lib/extensions.ts b/lib/extensions.ts index df7c082..eac6868 100644 --- a/lib/extensions.ts +++ b/lib/extensions.ts @@ -22,6 +22,8 @@ import * as crypto from "crypto"; import * as config from "./config"; import { Fault } from "./types"; import { ROOT_DIR } from "./config"; +import * as logger from "./logger"; +import readline from "readline"; const TIMEOUT = +config.get("EXT_TIMEOUT"); @@ -45,7 +47,7 @@ export function run(args: string[]): Promise<{ fault: Fault; value: any }> { if (!processes[scriptName]) { const p = spawn(ROOT_DIR + "/bin/genieacs-ext", [scriptName], { - stdio: ["inherit", "inherit", "inherit", "ipc"], + stdio: ["ignore", "pipe", "pipe", "ipc"], }); processes[scriptName] = p; @@ -69,6 +71,16 @@ export function run(args: string[]): Promise<{ fault: Fault; value: any }> { }); p.on("message", messageHandler); + + const rlstdout = readline.createInterface(p.stdout); + rlstdout.on("line", (line) => { + logger.info({ message: `Ext ${scriptName}(${p.pid}): ${line}` }); + }); + + const rlstderr = readline.createInterface(p.stderr); + rlstderr.on("line", (line) => { + logger.warn({ message: `Ext ${scriptName}(${p.pid}): ${line}` }); + }); } setTimeout(() => {