1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const cli_config_1 = require("./cli-config");
|
4 | const EventSource = require("eventsource");
|
5 | const auth_1 = require("./auth");
|
6 | const get_project_id_1 = require("./get-project-id");
|
7 | exports.streamLogs = (logType, prettyjson, filterBy, filterValue) => {
|
8 |
|
9 | const token = auth_1.auth.get('token');
|
10 | const projectId = get_project_id_1.getProjectId();
|
11 | const filters = filterBy && filterValue
|
12 | ? `&filterBy=${filterBy}&filterValue=${filterValue}`
|
13 | : '';
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | const url = `${cli_config_1.REALTIME_LOGS_URL}?token=${token}&projectId=${projectId}&logType=${logType}${filters}`;
|
20 | var source = new EventSource(url);
|
21 | source.addEventListener('put', (message) => {
|
22 | const logLines = JSON.parse(message.data);
|
23 | if (logLines.path === '/' && message.data !== null && logLines.data) {
|
24 | Object.values(logLines.data).forEach(line => {
|
25 | if (prettyjson) {
|
26 | console.log(JSON.stringify(line, null, 4));
|
27 | console.log();
|
28 | }
|
29 | else
|
30 | console.log(JSON.stringify(line));
|
31 | });
|
32 | }
|
33 | else if (message.data !== null && logLines && logLines.data) {
|
34 | if (prettyjson)
|
35 | console.log(JSON.stringify(logLines.data, null, 4));
|
36 | else
|
37 | console.log(JSON.stringify(logLines.data));
|
38 | }
|
39 | });
|
40 | source.onmessage = (e) => {
|
41 |
|
42 | };
|
43 | source.onerror = e => {
|
44 | console.log(e);
|
45 | process.exit();
|
46 | };
|
47 | };
|