From 1b337d729e64cde0bd345d0f0da04cbfc5aa02c5 Mon Sep 17 00:00:00 2001 From: Alexis Puga Date: Sat, 11 Sep 2021 04:34:43 -0500 Subject: [PATCH] STY: Prettify logging; make it verbose In brief: - Use bold font for "titles". - Use Dim magenta, and icons, for verbose logs. - Use an italic font for data logs. - Add command args to verbose logs. Update src/lib/log.js: - Use bold font for info logs. - Use italic font for data logs. - Use dim magenta font for verbose logs. Update bin/bli: - Remove ellipsis from log. Update src/handle-event.js: - Make status log verbose by printing the cmd and its args. - Show status log as verbose/error log. - Simplify status log: use ticks and cross icons for status log. Update src/lib/run-cmd.js: - Add newline before each info log. - Print cmd and its args as a verbose log. Update src/stop.js: - Add newline before end log. - Remove ellipsis from end log. Update test/integration/cli.test.js: - Remove ellipsis from commands. - Add newlines on end commands. --- bin/cli | 2 +- src/handle-event.js | 2 +- src/lib/log.js | 6 +++--- src/lib/run-cmd.js | 3 ++- src/stop.js | 2 +- test/integration/cli.test.js | 10 +++++----- 6 files changed, 13 insertions(+), 12 deletions(-) diff --git a/bin/cli b/bin/cli index ddec831..a7f0482 100755 --- a/bin/cli +++ b/bin/cli @@ -24,7 +24,7 @@ const { argv } = yargs(hideBin(process.argv)) }, async (argv) => { process.on('exit', shutdown) - log('info', 'Starting precise-watcher...') + log('info', 'Starting precise-watcher') await start(argv) }) .command('stop', 'Stop watching files.', {}, () => stop()) diff --git a/src/handle-event.js b/src/handle-event.js index 15b65d5..284bcb4 100644 --- a/src/handle-event.js +++ b/src/handle-event.js @@ -125,7 +125,7 @@ module.exports = (eventName, commands, { debug(`Running ${cmd}, args: ${JSON.stringify(cmdArgs)}, options: ${JSON.stringify(cmdOptions)}.`) runCmd(cmd, cmdArgs, cmdOptions).then(async (status) => { - log('info', `${cmd} exited with status ${status}`) + log(`${status > 0 ? 'error' : 'verbose'}`, `${status > 0 ? '✕' : '✓'} ${cmd} ${cmdArgs.join(' ')}`) if (serial) { debug('Calling next command in serial...') diff --git a/src/lib/log.js b/src/lib/log.js index b66f52d..eadf04e 100644 --- a/src/lib/log.js +++ b/src/lib/log.js @@ -3,10 +3,10 @@ const colors = require('colors/safe') colors.setTheme({ silly: 'rainbow', input: 'grey', - verbose: 'cyan', + verbose: ['dim', 'magenta'], prompt: 'grey', - info: 'green', - data: 'grey', + info: 'bold', + data: 'italic', help: 'cyan', warn: 'yellow', debug: 'blue', diff --git a/src/lib/run-cmd.js b/src/lib/run-cmd.js index 7f0e2a6..cdd5d53 100644 --- a/src/lib/run-cmd.js +++ b/src/lib/run-cmd.js @@ -5,7 +5,8 @@ module.exports = async (cmd, args, options) => await new Promise((resolve, rejec const child = spawn(cmd, args, options) const { stdout, stderr } = child - log('info', `Running ${cmd}`) + log('info', `\nRunning ${cmd}`) + log('verbose', `▸ ${cmd} ${args.join(' ')}`) stdout.on('data', (data) => { log('data', data.toString()) diff --git a/src/stop.js b/src/stop.js index c299078..fc822ee 100644 --- a/src/stop.js +++ b/src/stop.js @@ -6,7 +6,7 @@ const removeAllWatchers = async (watchers) => await Promise.all( ) module.exports = async (watchers) => { - log('info', 'Stopping precise-watcher...') + log('info', '\nStopping precise-watcher') if (!watchers) { debug('Removing all watchers.') diff --git a/test/integration/cli.test.js b/test/integration/cli.test.js index b90efee..c674711 100644 --- a/test/integration/cli.test.js +++ b/test/integration/cli.test.js @@ -23,8 +23,8 @@ describe('precise-watcher', () => { expect(stderr).toBe('') expect(stdout).toBe([ - 'Starting precise-watcher...', - 'Stopping precise-watcher...' + 'Starting precise-watcher', + '\nStopping precise-watcher' ].join('\n') + '\n') }) @@ -52,8 +52,8 @@ describe('precise-watcher', () => { expect(stderr).toMatch(`Setting config to ${config}`) expect(stderr).toMatch(`Reading ${path.join(cwd, config)}`) expect(stdout).toBe([ - 'Starting precise-watcher...', - 'Stopping precise-watcher...' + 'Starting precise-watcher', + '\nStopping precise-watcher' ].join('\n') + '\n') }) @@ -63,6 +63,6 @@ describe('precise-watcher', () => { }) expect(stderr).toBe('') - expect(stdout).toBe('Stopping precise-watcher...\n') + expect(stdout).toBe('\nStopping precise-watcher\n') }) })