From 7233667d496379f8730cdd52110e5a6e57855a7c Mon Sep 17 00:00:00 2001 From: Nicholas Penree Date: Wed, 11 Dec 2024 10:35:12 -0500 Subject: [PATCH] feat(logs): improvements to searching --- .../server/wss/docker-container-logs.ts | 39 ++++++++----------- .../server/src/wss/docker-container-logs.ts | 38 +++++++++--------- 2 files changed, 36 insertions(+), 41 deletions(-) diff --git a/apps/dokploy/server/wss/docker-container-logs.ts b/apps/dokploy/server/wss/docker-container-logs.ts index 4630d8fe5..1b28c11bc 100644 --- a/apps/dokploy/server/wss/docker-container-logs.ts +++ b/apps/dokploy/server/wss/docker-container-logs.ts @@ -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); diff --git a/packages/server/src/wss/docker-container-logs.ts b/packages/server/src/wss/docker-container-logs.ts index db9ce90b1..7cfdb8d61 100644 --- a/packages/server/src/wss/docker-container-logs.ts +++ b/packages/server/src/wss/docker-container-logs.ts @@ -55,9 +55,12 @@ export const setupDockerContainerLogsWebSocketServer = ( new Promise((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);