logs

package
v0.1.15 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package logs provides a shared log printer for CLI commands that consume enriched log events from the job-scoped SSE stream. The `ploy job follow` command delegates to this printer to ensure consistent formatting across all log-consuming commands.

This package uses the canonical stream.LogRecord type from internal/stream to ensure a single source of truth for log payload structures across the server publish path and CLI decode path. This eliminates duplicate struct definitions and prevents drift between server and CLI.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Format

type Format string

Format controls log rendering style.

const (
	// FormatStructured includes timestamp, stream labels, and execution context.
	FormatStructured Format = "structured"
	// FormatRaw prints log lines as-is (message only).
	FormatRaw Format = "raw"
)

type Printer

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

Printer formats and writes log records to an output stream. Thread-safe for use in SSE event handlers.

func NewPrinter

func NewPrinter(format Format, out io.Writer) *Printer

NewPrinter creates a log printer with the given format and output writer. If format is empty, defaults to FormatStructured. If out is nil, logs are discarded silently.

func (*Printer) Format

func (p *Printer) Format() Format

Format returns the printer's configured format.

func (*Printer) PrintLog

func (p *Printer) PrintLog(rec logstream.LogRecord)

PrintLog formats and writes a single log record.

Structured format (when enriched fields are present):

2025-10-22T10:00:00Z stdout node=<node_id> job_type=<job_type> step=<next_id> job=<job_id> Step started

Structured format (basic, no enriched fields):

2025-10-22T10:00:00Z stdout Step started

Raw format (message only):

Step started

func (*Printer) PrintRetentionSummary

func (p *Printer) PrintRetentionSummary()

PrintRetentionSummary outputs the stored retention hint, if any. Call this after all log events have been processed.

func (*Printer) RecordRetention

func (p *Printer) RecordRetention(hint logstream.RetentionHint)

RecordRetention stores a retention hint to be printed at stream completion. Only the last recorded hint is printed (calls overwrite previous hints).

Jump to

Keyboard shortcuts

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