Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở
#1,544 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
62/100
Loại issue
Tính năng
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
docker, node.js, typescript
Lĩnh vực
devtools, testing

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.
Ngôn ngữ chính
TypeScript
Star
2.6k
Fork
277
Merge trung bình
1 ngày 53 phút
Pull request đã merge (30 ngày)
58

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của testcontainers/testcontainers-node

Tất cả issue của testcontainers/testcontainers-node

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.