logger: inline logging for time indicators

This commit is contained in:
CanadaHonk 2023-04-07 00:03:33 +01:00
parent 0183dd9fc0
commit c87bdac5bb
3 changed files with 7 additions and 3 deletions

View File

@ -1,5 +1,5 @@
import { writeFile } from 'fs/promises';
import { log } from '../lib/logger.js';
import { log, logInline } from '../lib/logger.js';
import IPCApi from '../lib/ipc.js';
import LocalCDP from '../lib/local/cdp.js';
@ -11,7 +11,7 @@ import V8CacheApi from '../api/v8Cache.js';
const acquireTarget = async (CDP, filter = () => true) => {
let target;
log('acquiring target...');
logInline('acquiring target');
while (!target) {
process.stdout.write('.');

View File

@ -1,5 +1,5 @@
import { get } from 'http';
import { log } from './logger.js';
import { log, logInline } from './logger.js';
let WebSocket;
const logCDP = process.argv.includes('--cdp-logging');
@ -73,6 +73,8 @@ export default async ({ pipe: { pipeWrite, pipeRead } = {}, port }) => {
attempt();
});
logInline('fetching websocket url');
const wsUrl = await continualTrying(() => new Promise((resolve, reject) => get(`http://127.0.0.1:${port}/json/version`, res => {
let body = '';
res.on('data', chunk => body += chunk.toString());
@ -86,6 +88,7 @@ export default async ({ pipe: { pipeWrite, pipeRead } = {}, port }) => {
});
}).on('error', reject)));
console.log();
log('got main process target websocket url:', wsUrl);
const ws = new (await WebSocket).default(wsUrl);

View File

@ -1,5 +1,6 @@
const rgb = (r, g, b, msg) => `\x1b[38;2;${r};${g};${b}m${msg}\x1b[0m`;
export const log = (...args) => console.log(`[${rgb(88, 101, 242, 'Gluon')}]`, ...args);
export const logInline = (...args) => process.stdout.write(`[${rgb(88, 101, 242, 'Gluon')}] ${args.map(x => x.toString()).join(' ')}`);
export const dangerousAPI = (func, option, value) => console.warn(`[${rgb(88, 101, 242, 'Gluon')}] ${rgb(250, 120, 20, `Using ${option}: ${value} (${func}) is dangerous`)}`);