eventlog

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateDuration

func CalculateDuration(node *StateNode) float64

CalculateDuration calculates the total duration from node timing.

func CaptureModulePath

func CaptureModulePath() string

CaptureModulePath captures the Go module path from go.mod if present.

func CountSteps

func CountSteps(node *StateNode) (total, passed, failed, skipped int)

CountSteps counts steps by result in a StateNode tree.

Types

type Event

type Event struct {
	// Common fields
	ID       string    `yaml:"id"`
	Type     EventType `yaml:"type,omitempty"`
	Start    float64   `yaml:"start"`           // Seconds since run started
	Duration float64   `yaml:"duration"`        // Seconds
	Error    string    `yaml:"error,omitempty"` // Error message if failed

	// Step event fields
	Run         string `yaml:"run,omitempty"`
	Result      Result `yaml:"result,omitempty"`
	GoroutineID uint64 `yaml:"goroutine_id,omitempty"` // Only when debug is enabled

	// Command event fields
	Command  string   `yaml:"command,omitempty"`   // The actual command executed
	Dir      string   `yaml:"dir,omitempty"`       // Working directory
	Output   string   `yaml:"output,omitempty"`    // stdout output
	ExitCode int      `yaml:"exit_code,omitempty"` // Process exit code
	ParentID string   `yaml:"parent_id,omitempty"` // Parent step/job ID for $() commands
	Env      []string `yaml:"env,omitempty"`       // Environment variables (when debug enabled)
}

Event represents a single execution event in the log.

type EventType added in v0.5.2

type EventType string

EventType indicates the source of an event.

const (
	EventTypeStep          EventType = "step"          // Step execution event
	EventTypeSubstitution  EventType = "substitution"  // $() command substitution
	EventTypeInterpolation EventType = "interpolation" // Variable interpolation
)

EventType constants for different event sources.

type GitInfo

type GitInfo struct {
	Commit     string `yaml:"commit,omitempty"`
	Branch     string `yaml:"branch,omitempty"`
	RemoteURL  string `yaml:"remote_url,omitempty"`
	Repository string `yaml:"repository,omitempty"` // Extracted from remote URL
}

GitInfo contains git repository information.

func CaptureGitInfo

func CaptureGitInfo() *GitInfo

CaptureGitInfo captures git repository information.

type Log

type Log struct {
	Metadata RunMetadata `yaml:"metadata"`
	State    *StateNode  `yaml:"state"`
	Events   []*Event    `yaml:"events"`
	Summary  *RunSummary `yaml:"summary,omitempty"`
}

Log is the complete log structure written to YAML.

type LogEntry added in v0.5.2

type LogEntry struct {
	Type       EventType
	ID         string
	ParentID   string
	Command    string
	Dir        string
	Output     string
	Error      string
	ExitCode   int
	Start      float64
	DurationMs int64
	Env        []string
}

LogEntry is the input for LogCommand with named fields.

type Logger

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

Logger collects events during execution and writes the final log.

func NewLogger

func NewLogger(filePath, pipelineName, pipelineFile string, debug bool) *Logger

NewLogger creates a new event logger. If filePath is empty, returns nil (no logging occurs).

func (*Logger) GetElapsed

func (l *Logger) GetElapsed() float64

GetElapsed returns the current elapsed time in seconds.

func (*Logger) GetEvents

func (l *Logger) GetEvents() []*Event

GetEvents returns a copy of the events slice.

func (*Logger) GetStartTime

func (l *Logger) GetStartTime() time.Time

GetStartTime returns the start time of the run.

func (*Logger) LogCommand added in v0.5.2

func (l *Logger) LogCommand(entry LogEntry)

LogCommand logs a command execution with full details.

func (*Logger) LogExec

func (l *Logger) LogExec(result Result, id, run string, start float64, durationMs int64, err error)

LogExec logs a single execution event (one per exec).

func (*Logger) Write

func (l *Logger) Write(state *StateNode, summary *RunSummary) error

Write writes the final event log to the file.

type Result

type Result string

Result represents the final outcome of an execution.

const (
	ResultPass    Result = "pass"
	ResultFail    Result = "fail"
	ResultSkipped Result = "skipped"
)

Result constants for execution outcomes.

type RunMetadata

type RunMetadata struct {
	RunID      string    `yaml:"run_id"`
	CreatedAt  time.Time `yaml:"created_at"`
	Pipeline   string    `yaml:"pipeline,omitempty"`
	File       string    `yaml:"file,omitempty"`
	ModulePath string    `yaml:"module_path,omitempty"`
	Git        *GitInfo  `yaml:"git,omitempty"`
}

RunMetadata contains information about the execution environment.

type RunSummary

type RunSummary struct {
	Duration     float64 `yaml:"duration"`               // Total duration in seconds
	TotalSteps   int     `yaml:"total_steps"`            // Total steps executed
	PassedSteps  int     `yaml:"passed_steps"`           // Steps that passed
	FailedSteps  int     `yaml:"failed_steps"`           // Steps that failed
	SkippedSteps int     `yaml:"skipped_steps"`          // Steps that were skipped
	Result       Result  `yaml:"result"`                 // Overall result
	MemoryAlloc  uint64  `yaml:"memory_alloc,omitempty"` // Memory allocated in bytes
	Goroutines   int     `yaml:"goroutines,omitempty"`   // Number of goroutines running
}

RunSummary provides aggregate statistics for the run.

type RuntimeStats added in v0.3.0

type RuntimeStats struct {
	MemoryAlloc uint64
	Goroutines  int
}

RuntimeStats holds memory and goroutine statistics.

func CaptureRuntimeStats added in v0.3.0

func CaptureRuntimeStats() RuntimeStats

CaptureRuntimeStats captures current memory allocation and goroutine count.

type StateNode

type StateNode struct {
	Name      string       `yaml:"name"`
	ID        string       `yaml:"id,omitempty"`
	Status    string       `yaml:"status"` // Readable string: pending, running, passed, failed, skipped, conditional
	Result    Result       `yaml:"result,omitempty"`
	If        string       `yaml:"if,omitempty"` // Condition that was evaluated
	CreatedAt time.Time    `yaml:"created_at"`
	UpdatedAt time.Time    `yaml:"updated_at,omitempty"`
	Start     float64      `yaml:"start,omitempty"`    // Seconds offset from run start
	Duration  float64      `yaml:"duration,omitempty"` // Total duration in seconds
	Steps     int          `yaml:"steps,omitempty"`    // Number of steps executed (for jobs/workflow)
	Children  []*StateNode `yaml:"children,omitempty"`
}

StateNode represents a node in the execution state tree for YAML output.

func NodeToStateNode

func NodeToStateNode(node *treeview.Node) *StateNode

NodeToStateNode converts a treeview.Node to a StateNode for serialization.

func TreeNodeToStateNode

func TreeNodeToStateNode(node *treeview.TreeNode) *StateNode

TreeNodeToStateNode converts a treeview.TreeNode to a StateNode.

Jump to

Keyboard shortcuts

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