logstream

package
v0.0.0-...-8d0dba2 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package logstream reads task logs without retaining the file in memory.

Index

Constants

View Source
const (
	DefaultPageBytes = 64 << 10
	MaxPageBytes     = 1 << 20
)
View Source
const (
	// MaxLineBytes matches the process-output bound. Oversized evidence is an
	// explicit error rather than a silently truncated log line.
	MaxLineBytes = 4 * 1024 * 1024
)

Variables

View Source
var (
	ErrInvalidCursor    = errors.New("invalid log cursor or cursor selection mismatch")
	ErrInvalidPageSize  = errors.New("log page size must be between 4 and 1048576 bytes")
	ErrLogResetRequired = errors.New("log was replaced or truncated; start a new read without the cursor")
	ErrInvalidUTF8      = errors.New("log contains invalid UTF-8; inspect the log file directly")
)
View Source
var (
	ErrInvalidTail       = errors.New("log tail must not be negative")
	ErrLineTooLong       = errors.New("log line exceeds byte limit")
	ErrChangedDuringRead = errors.New("log changed while reading; retry to retrieve the current log")
)

Functions

func Stream

func Stream(ctx context.Context, path string, tail int, follow bool, emit func(string) error) error

Stream emits the last tail lines, then follows appends when requested. Zero means all lines. Follow mode waits for a newline before emitting a partial line; finite reads also emit the final unterminated line. Memory is bounded independently of the file size and requested tail count.

Types

type LogIdentity

type LogIdentity struct {
	InstanceID string `json:"instanceId"`
	RunID      string `json:"runId"`
	Task       string `json:"task"`
	AttemptID  string `json:"attemptId"`
}

func CursorIdentity

func CursorIdentity(token string) (LogIdentity, error)

CursorIdentity lets callers resolve retained evidence before touching a log. A cursor selects an attempt; it never authorizes a filesystem path.

type Page

type Page struct {
	LogIdentity
	Text         string `json:"text"`
	StartOffset  int64  `json:"startOffset"`
	EndOffset    int64  `json:"endOffset"`
	NextCursor   string `json:"nextCursor"`
	AtEnd        bool   `json:"atEnd"`
	PendingBytes int    `json:"pendingBytes"`
}

func ReadPage

func ReadPage(ctx context.Context, path string, identity LogIdentity, token string, limit int, terminal bool) (Page, error)

ReadPage preserves byte offsets and partial lines without splitting UTF-8. An incomplete final rune waits at its original offset while an attempt runs; terminal evidence reports malformed text explicitly instead of polling forever.

Jump to

Keyboard shortcuts

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