Skip to content

Commit 956db59

Browse files
committed
Allow getting logs for whole projects, not just single deployments, closes #43
1 parent b6d4005 commit 956db59

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/commands/logs.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ exports.handler = ({id}) =>
1414
return;
1515
}
1616

17-
console.log(chalk.bold('Getting logs for deployment:'), id);
17+
console.log(chalk.bold('Getting logs for deployment:'), id, '\n');
1818

1919
// services request url
2020
const remoteUrl = `${userConfig.endpoint}/logs/${id}`;
@@ -46,17 +46,21 @@ exports.handler = ({id}) =>
4646
const d = buf.toString();
4747
const lines = d.split('\n');
4848
lines
49-
.map(line => line.replace(/^\u0001.+?\d/, '').replace(/\n+$/, ''))
49+
.map(line => line.replace(/^\u0001.+?(\d)/g, '$1').replace(/\n+$/, ''))
5050
.filter(line => line && line.length > 0)
5151
.map(line => {
52+
if (line.startsWith('Logs for')) {
53+
return {date: null, msg: `${chalk.bold(line)}\n`};
54+
}
55+
5256
const parts = line.split(/\dZ\s/);
5357
const date = new Date(parts[0]);
5458
const msg = parts[1];
5559
return {date, msg};
5660
})
5761
.filter(({date, msg}) => date !== undefined && msg !== undefined)
5862
.map(({date, msg}) => ({
59-
date: isFinite(date) ? `${date.toLocaleDateString()} ${date.toLocaleTimeString()}` : ' ',
63+
date: date && isFinite(date) ? `${date.toLocaleDateString()} ${date.toLocaleTimeString()}` : ' ',
6064
msg,
6165
}))
6266
.map(({date, msg}) => `${chalk.gray(`${date}`)} ${msg}`)

test/logs.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ module.exports = () => {
1313
const date2 = '2017-05-18T15:16:40.212591019Z';
1414
const date3 = '2017-05-18T15:16:40.375554362Z';
1515
const dirtyLogs = [
16-
`\u0001\u0000\u0000\u0000\u0000\u0000\u00002${date1} yarn start v0.24.4`,
17-
`\u0001\u0000\u0000\u0000\u0000\u0000\u00000${date2} $ node index.js `,
18-
`\u0001\u0000\u0000\u0000\u0000\u0000\u00004${date3} Listening on port 80`,
16+
`\u0001\u0000\u0000\u0000\u0000\u0000\u0000g${date1} yarn start v0.24.4`,
17+
`\u0001\u0000\u0000\u0000\u0000\u0000\u0000${date2} $ node index.js `,
18+
`\u0001\u0000\u0000\u0000\u0000\u0000\u0000${date3} Listening on port 80`,
1919
'',
2020
];
2121

@@ -46,7 +46,7 @@ module.exports = () => {
4646
t.deepEqual(
4747
consoleSpy.args,
4848
[
49-
['Getting logs for deployment:', id],
49+
['Getting logs for deployment:', id, '\n'],
5050
[`${d1.toLocaleDateString()} ${d1.toLocaleTimeString()} yarn start v0.24.4`],
5151
[`${d2.toLocaleDateString()} ${d2.toLocaleTimeString()} $ node index.js `],
5252
[`${d3.toLocaleDateString()} ${d3.toLocaleTimeString()} Listening on port 80`],

0 commit comments

Comments
 (0)