Help us shape the future of Go! Take the 2026 Go Developer Survey

logcapture

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package logcapture streams every container's stdout/stderr in a block into one combined, interleaved log file for the block's whole lifetime, so a scenario failure has the product's own logs available, not only the client-side symptom.

Index

Constants

View Source
const EnvOut = "IT_LOG_OUT"

EnvOut overrides the default log capture output directory.

Variables

This section is empty.

Functions

This section is empty.

Types

type Sink

type Sink struct {
	// contains filtered or unexported fields
}

Sink resolves where each block's combined container log file is written.

func NewSink

func NewSink(root string) (*Sink, error)

NewSink creates a unique directory for a new log capture run beneath root, isolated beneath its own ".run-*" directory so a stale local run's log files are never mixed with a fresh run's.

func (*Sink) FileFor

func (s *Sink) FileFor(block string) (string, error)

FileFor returns the combined-log file path for the named block, creating its containing directory. Safe to call concurrently for different blocks.

func (*Sink) Root

func (s *Sink) Root() string

Root returns the sink's absolute root directory.

func (*Sink) SharedFileFor

func (s *Sink) SharedFileFor(component string) (string, error)

SharedFileFor returns the log file path for a component shared across blocks, creating its containing directory. Shared components are started once and outlive every block, so their output belongs to the run rather than to whichever block happened to start them. Safe to call concurrently for different components.

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

Writer streams many containers' log lines into one combined file, prefixed per component the way `docker compose up` interleaves its services' output. Every Consumer's Accept is a non-blocking send: a full buffer drops the line and counts it, rather than ever blocking the caller.

lines is never closed: a container's own log-producer goroutine (owned by testcontainers, not this package) keeps calling Accept for as long as the container exists, independent of when the block decides to Close its Writer — closing the channel itself would race that producer and panic on a send to a closed channel. Close instead signals stop and lets run drain whatever already arrived.

func NewWriter

func NewWriter(path string) (*Writer, error)

NewWriter creates path and starts the background goroutine that drains lines into it. Call Close when the block tears down to flush and release the file.

func (*Writer) Close

func (w *Writer) Close()

Close signals the writer goroutine to drain and flush what has already arrived, then waits for it to finish and closes the file. Safe to call once per Writer, and safe to call while a container's log producer is still delivering lines — Accept remains a harmless no-op send into an unread channel afterward, never a panic or a block.

func (*Writer) Consumer

func (w *Writer) Consumer(component string) testcontainers.LogConsumer

Consumer returns a testcontainers.LogConsumer that forwards a single component's log lines into this writer, tagged with component in the combined file.

func (*Writer) Dropped

func (w *Writer) Dropped() int64

Dropped reports how many lines were dropped for arriving faster than the writer goroutine could drain the buffer.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL