From 0575d59c1a58fc49d6c13ed41c1d4a7c8c5a6a8a Mon Sep 17 00:00:00 2001 From: Philipp Muens Date: Thu, 2 Mar 2017 11:00:52 +0100 Subject: [PATCH] Add color to log ouput --- logs/lib/retrieveLogs.js | 3 ++- logs/lib/retrieveLogs.test.js | 10 +++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/logs/lib/retrieveLogs.js b/logs/lib/retrieveLogs.js index 843cbf9..52fac0c 100644 --- a/logs/lib/retrieveLogs.js +++ b/logs/lib/retrieveLogs.js @@ -3,6 +3,7 @@ /* eslint no-use-before-define: 0 */ const BbPromise = require('bluebird'); +const chalk = require('chalk'); module.exports = { retrieveLogs() { @@ -42,7 +43,7 @@ module.exports = { } let output = logs.entries - .reduce((p, c, i) => p += `${c.timestamp}: ${c.textPayload}\n`, ''); //eslint-disable-line + .reduce((p, c, i) => p += `${chalk.grey(c.timestamp + ':')} ${c.textPayload}\n`, ''); //eslint-disable-line output = `Displaying the ${logs.entries.length} most recent log(s):\n\n${output}`; // prettify output output = output.slice(0, output.length - 1); // remove "\n---\n\n" for the last log entry diff --git a/logs/lib/retrieveLogs.test.js b/logs/lib/retrieveLogs.test.js index 6d46d30..41f293f 100644 --- a/logs/lib/retrieveLogs.test.js +++ b/logs/lib/retrieveLogs.test.js @@ -2,6 +2,7 @@ const sinon = require('sinon'); const BbPromise = require('bluebird'); +const chalk = require('chalk'); const GoogleProvider = require('../../provider/googleProvider'); const GoogleLogs = require('../googleLogs'); @@ -131,8 +132,10 @@ describe('RetrieveLogs', () => { ], }; + const logEntry1 = `${chalk.grey('1970-01-01 00:00:')} Entry 1`; + const logEntry2 = `${chalk.grey('1970-01-01 00:01:')} Entry 2`; const expectedOutput = - 'Displaying the 2 most recent log(s):\n\n1970-01-01 00:00: Entry 1\n1970-01-01 00:01: Entry 2'; + `Displaying the 2 most recent log(s):\n\n${logEntry1}\n${logEntry2}`; return googleLogs.printLogs(logs).then(() => { expect(consoleLogStub.calledWithExactly(expectedOutput)).toEqual(true); @@ -140,9 +143,10 @@ describe('RetrieveLogs', () => { }); it('should print a default message to the console when no logs were received', () => { - const date = new Date().toISOString().slice(0, 10); + const date = `${new Date().toISOString().slice(0, 10)}:`; + const logEntry = `${chalk.grey(date)} There is no log data to show...`; const expectedOutput = - `Displaying the 1 most recent log(s):\n\n${date}: There is no log data to show...`; + `Displaying the 1 most recent log(s):\n\n${logEntry}`; return googleLogs.printLogs({}).then(() => { expect(consoleLogStub.calledWithExactly(expectedOutput)).toEqual(true);