feat(logs): improvements to searching

This commit is contained in:
Nicholas Penree
2024-12-11 10:35:12 -05:00
parent 95cd410825
commit 7233667d49
2 changed files with 36 additions and 41 deletions

View File

@@ -55,10 +55,10 @@ export const setupDockerContainerLogsWebSocketServer = (
.once("ready", () => {
const baseCommand = `docker container logs --timestamps --tail ${tail} ${
since === "all" ? "" : `--since ${since}`
} --follow ${containerId}`;
const command = search
? `${baseCommand} 2>&1 | grep -iF '${search}'`
: baseCommand;
} --follow ${containerId}`;
const command = search
? `${baseCommand} 2>&1 | grep -iF '${search}'`
: baseCommand;
client.exec(command, (err, stream) => {
if (err) {
console.error("Execution error:", err);
@@ -98,25 +98,18 @@ export const setupDockerContainerLogsWebSocketServer = (
const shell = getShell();
const baseCommand = `docker container logs --timestamps --tail ${tail} ${
since === "all" ? "" : `--since ${since}`
} --follow ${containerId}`;
const command = search
? `${baseCommand} 2>&1 | grep -iF '${search}'`
: baseCommand;
const ptyProcess = spawn(
shell,
[
"-c",
command,
],
{
name: "xterm-256color",
cwd: process.env.HOME,
env: process.env,
encoding: "utf8",
cols: 80,
rows: 30,
},
);
} --follow ${containerId}`;
const command = search
? `${baseCommand} 2>&1 | grep -iF '${search}'`
: baseCommand;
const ptyProcess = spawn(shell, ["-c", command], {
name: "xterm-256color",
cwd: process.env.HOME,
env: process.env,
encoding: "utf8",
cols: 80,
rows: 30,
});
ptyProcess.onData((data) => {
ws.send(data);

View File

@@ -55,9 +55,12 @@ export const setupDockerContainerLogsWebSocketServer = (
new Promise<void>((resolve, reject) => {
client
.once("ready", () => {
const command = `
bash -c "docker container logs --timestamps --tail ${tail} ${since === "all" ? "" : `--since ${since}`} --follow ${containerId} | grep -iF '${search}'"
`;
const baseCommand = `docker container logs --timestamps --tail ${tail} ${
since === "all" ? "" : `--since ${since}`
} --follow ${containerId}`;
const command = search
? `${baseCommand} 2>&1 | grep -iF '${search}'`
: baseCommand;
client.exec(command, (err, stream) => {
if (err) {
console.error("Execution error:", err);
@@ -87,21 +90,20 @@ export const setupDockerContainerLogsWebSocketServer = (
});
} else {
const shell = getShell();
const ptyProcess = spawn(
shell,
[
"-c",
`docker container logs --timestamps --tail ${tail} ${since === "all" ? "" : `--since ${since}`} --follow ${containerId} | grep -iF '${search}'`,
],
{
name: "xterm-256color",
cwd: process.env.HOME,
env: process.env,
encoding: "utf8",
cols: 80,
rows: 30,
},
);
const baseCommand = `docker container logs --timestamps --tail ${tail} ${
since === "all" ? "" : `--since ${since}`
} --follow ${containerId}`;
const command = search
? `${baseCommand} 2>&1 | grep -iF '${search}'`
: baseCommand;
const ptyProcess = spawn(shell, ["-c", command], {
name: "xterm-256color",
cwd: process.env.HOME,
env: process.env,
encoding: "utf8",
cols: 80,
rows: 30,
});
ptyProcess.onData((data) => {
ws.send(data);