feat(logs): improvements to searching

This commit is contained in:
Nicholas Penree
2024-12-11 10:29:09 -05:00
parent 00f9e262a9
commit 95cd410825
4 changed files with 32 additions and 16 deletions

View File

@@ -32,7 +32,7 @@ export const setupDockerContainerLogsWebSocketServer = (
const containerId = url.searchParams.get("containerId");
const tail = url.searchParams.get("tail");
const search = url.searchParams.get("search");
const since = url.searchParams.get("since")
const since = url.searchParams.get("since");
const serverId = url.searchParams.get("serverId");
const { user, session } = await validateWebSocketRequest(req);
@@ -53,9 +53,12 @@ export const setupDockerContainerLogsWebSocketServer = (
const client = new Client();
client
.once("ready", () => {
const command = `
bash -c "docker container logs --timestamps --tail ${tail} ${since === "all" ? "" : `--since ${since}`} --follow ${containerId} | grep -i '${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);
@@ -93,11 +96,17 @@ export const setupDockerContainerLogsWebSocketServer = (
});
} else {
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",
`docker container logs --timestamps --tail ${tail} ${since === "all" ? "" : `--since ${since}`} --follow ${containerId} | grep -i '${search}'`,
command,
],
{
name: "xterm-256color",