Documentation
¶
Index ¶
Constants ¶
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.
const MaxDockerFrameSize = 1 << 20
MaxDockerFrameSize caps one frame of a multiplexed Docker log stream.
const TruncatedMarker = "...[truncated]"
TruncatedMarker is appended to a line that was cut at the line cap.
Variables ¶
var ErrDockerFrameTooLarge = errors.New("docker log frame exceeds size limit")
ErrDockerFrameTooLarge is returned when a frame header declares a payload larger than MaxDockerFrameSize.
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
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 (*Buffer) Unsubscribe ¶
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 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.