Documentation
¶
Overview ¶
Package progress provides timestamped logging to file and stdout with color support.
Index ¶
- func IsPathLockedByCurrentProcess(path string) bool
- func TryLockFile(f *os.File) (bool, error)
- type Colors
- type Config
- type Logger
- func (l *Logger) Close() error
- func (l *Logger) Elapsed() string
- func (l *Logger) Error(format string, args ...any)
- func (l *Logger) LogAnswer(answer string)
- func (l *Logger) LogDiffStats(files, additions, deletions int)
- func (l *Logger) LogDraftReview(action, feedback string)
- func (l *Logger) LogQuestion(question string, options []string)
- func (l *Logger) Path() string
- func (l *Logger) Print(format string, args ...any)
- func (l *Logger) PrintAligned(text string)
- func (l *Logger) PrintRaw(format string, args ...any)
- func (l *Logger) PrintSection(section status.Section)
- func (l *Logger) SetFailed(reason error)
- func (l *Logger) Warn(format string, args ...any)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsPathLockedByCurrentProcess ¶ added in v0.4.0
IsPathLockedByCurrentProcess reports whether this process holds the active lock for path.
Types ¶
type Colors ¶ added in v0.2.0
type Colors struct {
// contains filtered or unexported fields
}
Colors holds all color configuration for output formatting. use NewColors to create from config.ColorConfig.
func NewColors ¶ added in v0.2.0
func NewColors(cfg config.ColorConfig) *Colors
NewColors creates Colors from config.ColorConfig. all colors must be provided - use config with embedded defaults fallback. panics if any color value is invalid (configuration error).
type Config ¶
type Config struct {
PlanFile string // plan filename (used to derive progress filename)
PlanDescription string // plan description for plan mode (used for filename)
Mode string // execution mode: full, review, codex-only, plan
Branch string // current git branch
BranchOverride string // explicit branch name override (--branch flag); when set, used as filename stem instead of plan file
NoColor bool // disable color output (sets color.NoColor globally)
}
Config holds logger configuration.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger writes timestamped output to both file and stdout. writeMu serializes file + stdout writes so concurrent callers (e.g., codex stderr processor + rollout-file tailer both feeding OutputHandler) cannot interleave at byte level on the same fmt.Fprintf. The OS guarantees atomicity for individual small writes to a regular file or tty, but a single writeTimestamped call invokes both writeFile AND writeStdout, and we want those two writes (plus the inner fmt.Fprintf framing) to ship as one logical unit per concurrent producer.
func NewLogger ¶
NewLogger creates a logger writing to both a progress file and stdout. if the progress file already ends with a "Completed:" footer (successful run), it is truncated and a fresh header is written. if the file ended with a "Failed:" footer or has no footer (interrupted/failed run), the existing log is preserved and a restart separator is written so history carries across retries (issue #288). colors must be provided (created via NewColors from config). holder is the shared PhaseHolder for reading the current execution phase.
func (*Logger) Close ¶
Close writes footer, releases the file lock, and closes the progress file. Writes "Completed:" footer on success, or "Failed: ... - <reason>" if SetFailed was called with a non-nil error. Holds l.writeMu across the footer write sequence so a concurrent in-flight Print or PrintAligned cannot split the separator from the Completed/Failed line.
func (*Logger) Elapsed ¶
Elapsed returns formatted elapsed time since start. for durations >= 1 hour, truncates to minutes (e.g. "1h23m"); otherwise to seconds (e.g. "5m30s").
func (*Logger) LogAnswer ¶ added in v0.4.0
LogAnswer logs the user's answer for plan creation mode. format: ANSWER: <answer>
func (*Logger) LogDiffStats ¶ added in v0.10.0
LogDiffStats writes git diff stats to the progress file (file-only, no stdout). format: [timestamp] DIFFSTATS: files=F additions=A deletions=D Takes l.writeMu so a concurrent producer mid-pair (e.g., Print holding the mutex across its file + stdout sequence) cannot have this single write slip between its two sinks.
func (*Logger) LogDraftReview ¶ added in v0.6.0
LogDraftReview logs the user's draft review action and optional feedback. format: DRAFT REVIEW: <action> if feedback is non-empty: FEEDBACK: <feedback> Holds l.writeMu across the full 2- or 4-write sequence so the DRAFT REVIEW and FEEDBACK lines stay grouped on both sinks under concurrent producers.
func (*Logger) LogQuestion ¶ added in v0.4.0
LogQuestion logs a question and its options for plan creation mode. format: QUESTION: <question>\n OPTIONS: <opt1>, <opt2>, ... Holds l.writeMu across the full 4-write sequence so another producer cannot split the QUESTION line from its companion OPTIONS line on either sink.
func (*Logger) PrintAligned ¶
PrintAligned writes text with timestamp on each line, suppressing empty lines.
func (*Logger) PrintRaw ¶
PrintRaw writes without timestamp (for streaming output). Holds l.writeMu across the file + stdout pair, see writeTimestamped.
func (*Logger) PrintSection ¶
PrintSection writes a section header without timestamp in yellow. format: "\n--- {label} ---\n" Holds l.writeMu across the file + stdout pair, see writeTimestamped.
func (*Logger) SetFailed ¶ added in v0.27.3
SetFailed marks the logger as failed with the given reason. On Close, a "Failed:" footer is written instead of "Completed:", so the restart path appends to the file (preserving history) rather than truncating. Safe to call multiple times; the most recent call wins (passing nil clears any previous failure state).