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

@@ -102,21 +102,14 @@ export const setupDockerContainerLogsWebSocketServer = (
const command = search const command = search
? `${baseCommand} 2>&1 | grep -iF '${search}'` ? `${baseCommand} 2>&1 | grep -iF '${search}'`
: baseCommand; : baseCommand;
const ptyProcess = spawn( const ptyProcess = spawn(shell, ["-c", command], {
shell,
[
"-c",
command,
],
{
name: "xterm-256color", name: "xterm-256color",
cwd: process.env.HOME, cwd: process.env.HOME,
env: process.env, env: process.env,
encoding: "utf8", encoding: "utf8",
cols: 80, cols: 80,
rows: 30, rows: 30,
}, });
);
ptyProcess.onData((data) => { ptyProcess.onData((data) => {
ws.send(data); ws.send(data);

View File

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