Skip to content

Commit 772839f

Browse files
authored
Merge pull request #38 from serverless/add-color-to-log-output
Add color to log ouput
2 parents a1ac495 + 0575d59 commit 772839f

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

logs/lib/retrieveLogs.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/* eslint no-use-before-define: 0 */
44

55
const BbPromise = require('bluebird');
6+
const chalk = require('chalk');
67

78
module.exports = {
89
retrieveLogs() {
@@ -42,7 +43,7 @@ module.exports = {
4243
}
4344

4445
let output = logs.entries
45-
.reduce((p, c, i) => p += `${c.timestamp}: ${c.textPayload}\n`, ''); //eslint-disable-line
46+
.reduce((p, c, i) => p += `${chalk.grey(c.timestamp + ':')} ${c.textPayload}\n`, ''); //eslint-disable-line
4647

4748
output = `Displaying the ${logs.entries.length} most recent log(s):\n\n${output}`; // prettify output
4849
output = output.slice(0, output.length - 1); // remove "\n---\n\n" for the last log entry

logs/lib/retrieveLogs.test.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const sinon = require('sinon');
44
const BbPromise = require('bluebird');
5+
const chalk = require('chalk');
56

67
const GoogleProvider = require('../../provider/googleProvider');
78
const GoogleLogs = require('../googleLogs');
@@ -131,18 +132,21 @@ describe('RetrieveLogs', () => {
131132
],
132133
};
133134

135+
const logEntry1 = `${chalk.grey('1970-01-01 00:00:')} Entry 1`;
136+
const logEntry2 = `${chalk.grey('1970-01-01 00:01:')} Entry 2`;
134137
const expectedOutput =
135-
'Displaying the 2 most recent log(s):\n\n1970-01-01 00:00: Entry 1\n1970-01-01 00:01: Entry 2';
138+
`Displaying the 2 most recent log(s):\n\n${logEntry1}\n${logEntry2}`;
136139

137140
return googleLogs.printLogs(logs).then(() => {
138141
expect(consoleLogStub.calledWithExactly(expectedOutput)).toEqual(true);
139142
});
140143
});
141144

142145
it('should print a default message to the console when no logs were received', () => {
143-
const date = new Date().toISOString().slice(0, 10);
146+
const date = `${new Date().toISOString().slice(0, 10)}:`;
147+
const logEntry = `${chalk.grey(date)} There is no log data to show...`;
144148
const expectedOutput =
145-
`Displaying the 1 most recent log(s):\n\n${date}: There is no log data to show...`;
149+
`Displaying the 1 most recent log(s):\n\n${logEntry}`;
146150

147151
return googleLogs.printLogs({}).then(() => {
148152
expect(consoleLogStub.calledWithExactly(expectedOutput)).toEqual(true);

0 commit comments

Comments
 (0)