Merge pull request #3 from philippdieter/main
Port some of my previous commits
This commit is contained in:
commit
54e997e88f
8
index.js
8
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}`);
|
||||
|
||||
ws.onopen = () => {
|
||||
configure(ws, defaultConsole);
|
||||
|
||||
ws.onopen = () => {
|
||||
console.log('[TERMLOG]: Connected');
|
||||
};
|
||||
|
||||
|
14
server.js
14
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
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user