From 246935bde6cc3da2a0c873b3c902f08cabcafa43 Mon Sep 17 00:00:00 2001 From: Philipp Dieter Date: Sat, 28 Aug 2021 18:14:47 +0200 Subject: [PATCH 1/5] Add log level info, update help texts --- index.js | 5 +++++ server.js | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index c7dae01..93f731b 100755 --- a/index.js +++ b/index.js @@ -6,6 +6,11 @@ const configure = (conn, defaultConsole) => { if (console._tsconsole_configured) return; console._tsconsole_configured = true; + console.info = (...args) => { + sendWhenConnected(conn, JSON.stringify({ type: 'info', data: Array.from(args) , }), defaultConsole); + defaultConsole.info.apply(defaultConsole, args); + }; + console.log = (...args) => { sendWhenConnected(conn, JSON.stringify({ type: 'log', data: Array.from(args) , }), defaultConsole); defaultConsole.log.apply(defaultConsole, args); diff --git a/server.js b/server.js index f8cbb1a..456ec1e 100755 --- a/server.js +++ b/server.js @@ -11,7 +11,7 @@ const CYellow = "\x1b[33m"; const CWhite = "\x1b[37m"; const CBlue = "\x1b[34m"; -const LOGLEVELS = ['log', 'warn', 'error', 'debug']; +const LOGLEVELS = ['info', 'log', 'warn', 'error', 'debug']; // global var keeping track of what to display let SHOWLEVELS = LOGLEVELS; @@ -137,7 +137,7 @@ const startServer = (options) => { // Start a node repl const r = repl.start({prompt: "> "}); r.defineCommand('show', { - help: '[TERMLOG] Select log levels to display (info | warning | error | debug). Multiple levels are seperated by `,`', + help: '[TERMLOG] Select log levels to display (info | log | warning | error | debug). Multiple levels are seperated by `,`', action(arg) { const args = arg.split(","); applyShowFilter(args); @@ -172,7 +172,7 @@ Options: Save output to file --show args - Select log levels to display (info | warning | error | debug). Multiple levels are seperated by \`,\` + Select log levels to display (info | log | warning | error | debug). Multiple levels are seperated by \`,\` `); } else { From 14f825cb51916a41929a46439434c445b3e46fd4 Mon Sep 17 00:00:00 2001 From: Philipp Dieter Date: Sat, 28 Aug 2021 18:15:22 +0200 Subject: [PATCH 2/5] Add option to set prompt for server --- server.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/server.js b/server.js index 456ec1e..b709719 100755 --- a/server.js +++ b/server.js @@ -5,6 +5,7 @@ const repl = require('repl'); const DEFAULT_HOST = "localhost"; const DEFAULT_PORT = 3456; +const DEFAULT_PROMPT = "> "; const CRed = "\x1b[31m"; const CYellow = "\x1b[33m"; @@ -135,7 +136,7 @@ const startServer = (options) => { }) // Start a node repl - const r = repl.start({prompt: "> "}); + const r = repl.start({prompt: options.prompt}); r.defineCommand('show', { help: '[TERMLOG] Select log levels to display (info | log | warning | error | debug). Multiple levels are seperated by `,`', action(arg) { @@ -171,6 +172,9 @@ Options: --out arg Save output to file +--primpt arg + Sets promt, "" to disable + --show args Select log levels to display (info | log | warning | error | debug). Multiple levels are seperated by \`,\` @@ -183,6 +187,7 @@ Options: port: DEFAULT_PORT, host:DEFAULT_HOST, show: LOGLEVELS, + prompt: DEFAULT_PROMPT, ...args } From 0822e06f17ff747987d015166116c9d6a6e29a22 Mon Sep 17 00:00:00 2001 From: Philipp Dieter Date: Sat, 28 Aug 2021 18:17:11 +0200 Subject: [PATCH 3/5] Beautify output when its an object, indent multiline output --- server.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/server.js b/server.js index b709719..e55db22 100755 --- a/server.js +++ b/server.js @@ -32,6 +32,12 @@ const out = (data, color = CWhite) => { if (!Array.isArray(data)) data = [data]; process.stdout.write(color); process.stdout.write(getTime() + " "); + + if (typeof data[0] === 'object') { + data[0] = JSON.stringify(data[0], null, 2); + } + data[0] = data[0].replace(/\n/g, '\n | '); + console.log.apply(console, data); process.stdout.write(CWhite); } From 9d7ec3adcb431a67d8fd7c791f6a42354821593a Mon Sep 17 00:00:00 2001 From: Philipp Dieter Date: Sat, 28 Aug 2021 18:17:26 +0200 Subject: [PATCH 4/5] Run configure before ws connect to catch early console output --- index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 93f731b..d867d13 100755 --- a/index.js +++ b/index.js @@ -54,8 +54,9 @@ const termlog = (options = {}) => { const ws = new WebSocket(`${options.ssl ? "wss" : "ws"}://${options.host}:${options.port}`); + configure(ws, defaultConsole); + ws.onopen = () => { - configure(ws, defaultConsole); console.log('[TERMLOG]: Connected'); }; From 62bcad5b081a677631ca9bdf070e43372328f5fc Mon Sep 17 00:00:00 2001 From: Philipp Dieter Date: Mon, 30 Aug 2021 23:14:15 +0200 Subject: [PATCH 5/5] Remove inconsistent output formatting --- server.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/server.js b/server.js index e55db22..b09748f 100755 --- a/server.js +++ b/server.js @@ -33,11 +33,6 @@ const out = (data, color = CWhite) => { process.stdout.write(color); process.stdout.write(getTime() + " "); - if (typeof data[0] === 'object') { - data[0] = JSON.stringify(data[0], null, 2); - } - data[0] = data[0].replace(/\n/g, '\n | '); - console.log.apply(console, data); process.stdout.write(CWhite); }