Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta
#1,544 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
62/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
docker, node.js, typescript
Ambito
devtools, testing

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.
Lingua principale
TypeScript
Stelle
2.6k
Fork
274
Merge medio
1g 14h
PR unite (30g)
44

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di testcontainers/testcontainers-node

Tutte le issue di testcontainers/testcontainers-node

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.