diff --git a/index.js b/index.js index c7dae01..d867d13 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); @@ -49,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'); }; diff --git a/server.js b/server.js index f8cbb1a..b09748f 100755 --- a/server.js +++ b/server.js @@ -5,13 +5,14 @@ const repl = require('repl'); const DEFAULT_HOST = "localhost"; const DEFAULT_PORT = 3456; +const DEFAULT_PROMPT = "> "; const CRed = "\x1b[31m"; 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; @@ -31,6 +32,7 @@ const out = (data, color = CWhite) => { if (!Array.isArray(data)) data = [data]; process.stdout.write(color); process.stdout.write(getTime() + " "); + console.log.apply(console, data); process.stdout.write(CWhite); } @@ -135,9 +137,9 @@ 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 | 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); @@ -171,8 +173,11 @@ Options: --out arg Save output to file +--primpt arg + Sets promt, "" to disable + --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 { @@ -183,6 +188,7 @@ Options: port: DEFAULT_PORT, host:DEFAULT_HOST, show: LOGLEVELS, + prompt: DEFAULT_PROMPT, ...args }