Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Add `getLogs()` and a line-based log consumer

Abierto
#1,544 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
62/100
Tipo de issue
Nueva funcionalidad
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
docker, node.js, typescript
Área
devtools, testing

Línea de trabajo

Read logs in packages/testcontainers/src/generic-<container>/started-generic-<container>.ts, withLogConsumer in packages/testcontainers/src/generic-<container>/generic-<container>.ts, and the StartedTestContainer interface and forwarder in packages/testcontainers/src/test-<container>.ts. Trace how the existing streams expose stdout and stderr, then add the string retrieval options and a distinct line consumer while preserving stream access. Done when the documented examples work and the API changes are covered.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

enhancement minor

What happens

Reading a container's logs takes stream handling in both places it is offered.

After start, logs() resolves to a Readable. Getting text to assert on means collecting it by hand:

const stream = await container.logs();
const lines: string[] = [];
stream.on("data", (line) => lines.push(line));
await new Promise((resolve) => stream.on("end", resolve));

Before start, withLogConsumer hands over the raw stream, with stderr delivered on a custom err event:

.withLogConsumer((stream) => {
  stream.on("data", (line) => console.log(line));
  stream.on("err", (line) => console.error(line));
  stream.on("end", () => console.log("Stream closed"));
})

Expected

  • await container.getLogs() resolves to the logs so far as a string, with options for since, tail and stdout/stderr.
  • A line-based consumer, so the common case is one line: .withLogConsumer((line) => console.log(line)) or a helper such as LogConsumers.toConsole({ prefix: "redis" }).
  • The stream forms stay for callers who want them.

Where

  • logs in packages/testcontainers/src/generic-container/started-generic-container.ts
  • withLogConsumer in packages/testcontainers/src/generic-container/generic-container.ts
  • packages/testcontainers/src/test-container.ts

Notes

  • Java has String getLogs() and getLogs(OutputType...), and withLogConsumer(Consumer<OutputFrame>), where each frame carries its text and whether it is stdout or stderr. Go's LogConsumer.Accept(Log) is also per entry.
  • A function argument cannot tell a line consumer from a stream consumer, so the line form needs its own method name or a helper that returns a stream consumer.
  • Related: #1506. A string of recent logs is also what a start failure wants to include.

Dependencies

  • Nothing blocks this. It can start now.
  • Changes StartedTestContainer, which today means the interface, StartedGenericContainer and the forwarder on AbstractStartedContainer. Several other issues do the same. The edits do not overlap, so they can go in parallel.
Lenguaje dominante
TypeScript
Estrellas
2.6k
Forks
274
Merge medio
1 d 14 h
PR fusionados (30 d)
44

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de testcontainers/testcontainers-node

Todos los issues de testcontainers/testcontainers-node

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.