-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlogs.ts
More file actions
53 lines (44 loc) · 1.17 KB
/
logs.ts
File metadata and controls
53 lines (44 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { spawn } from "node:child_process";
import type { ChildProcess } from "node:child_process";
import { commands } from "vscode";
import { createPlugin } from "../plugins.ts";
import { pipeToLogOutputChannel } from "../utils/spawn.ts";
export default createPlugin(
"logs",
({ context, outputChannel, containerStatusTracker }) => {
context.subscriptions.push(
commands.registerCommand("localstack.viewLogs", () => {
outputChannel.show(true);
}),
);
let logsProcess: ChildProcess | undefined;
const startLogging = () => {
logsProcess?.kill();
const now = Math.floor(Date.now() / 1000);
logsProcess = spawn(
"docker",
["logs", "localstack-main", "--follow", "--since", String(now)],
{
stdio: "pipe",
},
);
pipeToLogOutputChannel(logsProcess, outputChannel, "[localstack.logs]: ");
};
const stopLogging = () => {
logsProcess?.kill();
logsProcess = undefined;
};
containerStatusTracker.onChange((status) => {
if (status === "running") {
startLogging();
} else if (status === "stopped") {
stopLogging();
}
});
context.subscriptions.push({
dispose() {
logsProcess?.kill();
},
});
},
);