From a03e821c023a21d2676cafc921971dfe7def7160 Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Tue, 8 Sep 2020 12:57:24 +0000 Subject: [PATCH] fix(core): update --- ts/smartlog.classes.smartlog.ts | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/ts/smartlog.classes.smartlog.ts b/ts/smartlog.classes.smartlog.ts index 61bfe45..6cf29be 100644 --- a/ts/smartlog.classes.smartlog.ts +++ b/ts/smartlog.classes.smartlog.ts @@ -34,7 +34,37 @@ export class Smartlog implements plugins.smartlogInterfaces.ILogDestination { /** * enables console logging */ - public enableConsole(optionsArg?: { }) { + public enableConsole(optionsArg?: { captureAll: boolean }) { + if (globalThis.process && optionsArg && optionsArg.captureAll) { + const process = globalThis.process; + const write = process.stdout.write; + process.stdout.write = (...args) => { + const logString: string = args[0]; + if (!logString.startsWith('LOG') && typeof logString === 'string') { + switch (true) { + case logString.substr(0, 20).includes('Error:'): + this.log('error', logString); + break; + default: + this.log('info', logString); + } + return; + } + // fileStream.write(args[0]); + write.apply(process.stdout, args); + return true; + }; + + process.stderr.write = (...args) => { + if (!args[0].startsWith('LOG')) { + this.log('error', args[0]); + return; + } + // fileStream.write(args[0]); + write.apply(process.stderr, args); + return true; + }; + } this.consoleEnabled = true; }