output

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Functions

func ResolveLayout added in v1.0.4

func ResolveLayout(ts *ast.Timestamps) (string, bool, error)

ResolveLayout returns the Go time layout to use given the tri-state value from the AST. Format may be a strftime string; it is translated to Go's reference-time layout. Returns layout, ok — ok is false when the value is unset or explicitly disabled.

func StrftimeToGoLayout added in v1.0.4

func StrftimeToGoLayout(f string) (string, error)

StrftimeToGoLayout translates a small strftime subset into the Go time layout that Time.Format understands. The subset is deliberately narrow — the ticket calls out the supported tokens explicitly rather than promising full glibc parity.

Supported:

%Y  four-digit year (2006)
%m  zero-padded month (01)
%d  zero-padded day of month (02)
%H  zero-padded hour 00-23 (15)
%M  zero-padded minute (04)
%S  zero-padded second (05)
%L  zero-padded 3-digit millisecond (.000, dot-prefixed by Go's layout)
%z  timezone offset ±hhmm (-0700)
%%  literal %

%L renders as ".000" so the dot separator is part of the field — same as `ts -s %.S`. Users who want the millis without a dot should use a custom layout; we don't try to fake sub-field arithmetic here.

Types

type CloseFunc

type CloseFunc func(err error) error

type Group

type Group struct {
	Begin, End string
	ErrorOnly  bool
}

func (Group) WrapWriter

func (g Group) WrapWriter(stdOut, _ io.Writer, _ string, cache *templater.Cache) (io.Writer, io.Writer, CloseFunc)

type Interleaved

type Interleaved struct{}

func (Interleaved) WrapWriter

func (Interleaved) WrapWriter(stdOut, stdErr io.Writer, _ string, _ *templater.Cache) (io.Writer, io.Writer, CloseFunc)

type Output

type Output interface {
	WrapWriter(stdOut, stdErr io.Writer, prefix string, cache *templater.Cache) (io.Writer, io.Writer, CloseFunc)
}

func BuildFor

func BuildFor(o *ast.Output, logger *logger.Logger) (Output, error)

Build the Output for the requested ast.Output.

type Prefixed

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

func NewPrefixed

func NewPrefixed(logger *logger.Logger) *Prefixed

func (*Prefixed) WrapWriter

func (p *Prefixed) WrapWriter(stdOut, _ io.Writer, prefix string, _ *templater.Cache) (io.Writer, io.Writer, CloseFunc)

type TimestampClock added in v1.0.4

type TimestampClock func() time.Time

TimestampClock is the clock used by the timestamping writer. Swappable for tests that need a deterministic now() — production callers leave it nil and get time.Now.

type TimestampSink added in v1.0.4

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

TimestampSink is the shared downstream target for a family of TimestampWriters. Sharing a sink, or sharing a *sync.Mutex across a pair of sinks (one for stdout, one for stderr), is how stdout + stderr + logger end up serialized into a single timestamped stream even though the underlying file descriptors remain separate.

func NewTimestampSink added in v1.0.4

func NewTimestampSink(w io.Writer, layout string, clock TimestampClock, sharedMu *sync.Mutex) *TimestampSink

NewTimestampSink builds a sink that writes to w, formatting timestamps with layout (a Go time layout, already translated from strftime if needed). If clock is nil, time.Now is used and timestamps are rendered in UTC. If sharedMu is non-nil it is used to serialize emissions across multiple sinks — the ticket calls for stdout+stderr to merge into a single timestamped view; passing one mutex to both sinks produces that without collapsing the two FDs.

The default layout is applied with t.UTC() so host TZ never leaks into it — the SPEC says the default is always GMT. User-supplied strftime formats render in local time unless the format itself asks for UTC (e.g. a literal `Z`), matching `ts(1)` behavior and letting users who want local timestamps actually get them.

type TimestampWriter added in v1.0.4

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

TimestampWriter wraps an io.Writer and prefixes every emitted line with a formatted timestamp. Partial writes (no trailing `\n`) are buffered until either a newline arrives or Close is called; a final unterminated segment is flushed with its own timestamp plus an appended `\n` so log consumers never see half-timestamped output.

Multiple TimestampWriter instances that share the same *TimestampSink merge their lines onto the same underlying writer under one mutex, so cmd stdout + stderr + rite-logger lines appear as one unified stream even when they race. Each call to Write treats every complete `\n`-terminated run as a single emission — the timestamp is captured when Write is called, not when the line originally arrived on stdout, but Go's cmd plumbing flushes on newline, so the skew is bounded by Go's own scheduler latency rather than by anything we add.

func NewTimestampWriter added in v1.0.4

func NewTimestampWriter(sink *TimestampSink) *TimestampWriter

NewTimestampWriter creates a writer that prefixes lines with the sink's timestamp layout before forwarding to the sink's underlying writer.

func (*TimestampWriter) Close added in v1.0.4

func (tw *TimestampWriter) Close() error

Close flushes any remaining buffered content (appending a newline if the final segment is unterminated) and marks the writer closed. Subsequent Writes return io.ErrClosedPipe.

func (*TimestampWriter) Write added in v1.0.4

func (tw *TimestampWriter) Write(p []byte) (int, error)

Write buffers input, emitting a timestamped line for each newline- terminated segment. Partial trailing text stays in the buffer until the next Write or Close.

Jump to

Keyboard shortcuts

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