Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

オープン
#1,544 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
62/100
issue の種類
機能追加
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
docker, node.js, typescript
領域
devtools, testing

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.
主要言語
TypeScript
スター
2.6k
フォーク
274
平均マージ
1日 14時間
マージ済み PR(30日)
44

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

testcontainers/testcontainers-node のほかの issue

testcontainers/testcontainers-node の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。