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", () => { .once("ready", () => {
const baseCommand = `docker container logs --timestamps --tail ${tail} ${ const baseCommand = `docker container logs --timestamps --tail ${tail} ${
since === "all" ? "" : `--since ${since}` since === "all" ? "" : `--since ${since}`
} --follow ${containerId}`; } --follow ${containerId}`;
const command = search const command = search
? `${baseCommand} 2>&1 | grep -iF '${search}'` ? `${baseCommand} 2>&1 | grep -iF '${search}'`
: baseCommand; : 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);
@@ -98,25 +98,18 @@ export const setupDockerContainerLogsWebSocketServer = (
const shell = getShell(); const shell = getShell();
const baseCommand = `docker container logs --timestamps --tail ${tail} ${ const baseCommand = `docker container logs --timestamps --tail ${tail} ${
since === "all" ? "" : `--since ${since}` since === "all" ? "" : `--since ${since}`
} --follow ${containerId}`; } --follow ${containerId}`;
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, name: "xterm-256color",
[ cwd: process.env.HOME,
"-c", env: process.env,
command, encoding: "utf8",
], cols: 80,
{ rows: 30,
name: "xterm-256color", });
cwd: process.env.HOME,
env: process.env,
encoding: "utf8",
cols: 80,
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);