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

logbuf

package
v1.4.3 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultTeeLineCap = 256 * 1024

DefaultTeeLineCap bounds a single captured line in Tee. Longer lines are truncated for the capture sink; the original output is never altered.

View Source
const MaxDockerFrameSize = 1 << 20

MaxDockerFrameSize caps one frame of a multiplexed Docker log stream.

View Source
const TruncatedMarker = "...[truncated]"

TruncatedMarker is appended to a line that was cut at the line cap.

Variables

View Source
var ErrDockerFrameTooLarge = errors.New("docker log frame exceeds size limit")

ErrDockerFrameTooLarge is returned when a frame header declares a payload larger than MaxDockerFrameSize.

View Source
var ErrDockerStreamCorrupt = errors.New("corrupt docker log stream")

ErrDockerStreamCorrupt is returned for a malformed frame header or a stream cut off mid-frame.

Functions

func Tee added in v1.4.3

func Tee(r io.Reader, orig, sink io.Writer, lineCap int)

Tee copies everything read from r to orig unchanged and writes one line at a time to sink. It drains r until EOF (or until r is closed) no matter what: write errors on orig or sink are ignored and over-long lines are truncated for sink, because a stalled reader fills the pipe and then blocks every write to the process's stdout/stderr. On a read error other than EOF it stops line capture, keeps forwarding raw bytes to orig and retries with a capped backoff; it never gives up on its own.

Types

type Buffer

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

func New

func New(size int) *Buffer

func (*Buffer) Clear

func (b *Buffer) Clear()

func (*Buffer) MaxSize

func (b *Buffer) MaxSize() int

func (*Buffer) Recent

func (b *Buffer) Recent(limit int) []Entry

func (*Buffer) Subscribe

func (b *Buffer) Subscribe() chan Entry

func (*Buffer) Unsubscribe

func (b *Buffer) Unsubscribe(ch chan Entry)

func (*Buffer) Write

func (b *Buffer) Write(p []byte) (int, error)

type DockerStreamReader added in v1.4.3

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

DockerStreamReader demultiplexes the framing Docker uses for logs of containers without a TTY: an 8-byte header (stream id, three zero bytes, big-endian uint32 payload size) followed by the payload. The declared size is not trusted: frames larger than MaxDockerFrameSize are rejected instead of allocated. Streams of TTY containers are not framed and must not be passed through this reader.

func NewDockerStreamReader added in v1.4.3

func NewDockerStreamReader(r io.Reader) *DockerStreamReader

NewDockerStreamReader wraps a multiplexed (non-TTY) Docker log stream.

func (*DockerStreamReader) Next added in v1.4.3

func (d *DockerStreamReader) Next() (string, []byte, error)

Next returns the next frame's stream name ("stdout" or "stderr") and its payload. The payload slice is reused by the following call. It returns io.EOF at a clean end of stream. A daemon error frame (stream id 3) is returned as an error carrying the daemon's message.

type Entry

type Entry struct {
	Timestamp time.Time `json:"timestamp"`
	Message   string    `json:"message"`
}

type LineSplitter added in v1.4.3

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

LineSplitter turns a byte stream into newline-delimited lines. A line longer than the cap is truncated (TruncatedMarker appended) and the rest of it is discarded up to the next newline, so memory stays bounded by the cap no matter how long a line is and the splitter never stops consuming.

func NewLineSplitter added in v1.4.3

func NewLineSplitter(max int, emit func(line []byte)) *LineSplitter

NewLineSplitter returns a splitter that calls emit once per line, without the trailing newline. The slice passed to emit is only valid during the call. max <= 0 means DefaultTeeLineCap.

func (*LineSplitter) Flush added in v1.4.3

func (s *LineSplitter) Flush()

Flush emits a buffered partial line, if any.

func (*LineSplitter) Write added in v1.4.3

func (s *LineSplitter) Write(p []byte) (int, error)

Write implements io.Writer. It never returns an error.

Jump to

Keyboard shortcuts

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