steplogger

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package steplogger provides interfaces and implementations for logging operational steps during runtime operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithLogger

func WithLogger(ctx context.Context, logger StepLogger) context.Context

WithLogger returns a new context with the logger attached.

Types

type StepLogger

type StepLogger interface {
	// Start begins a new step with the given messages.
	// The inProgress message is shown while the step is running.
	// The completed message is shown when the step completes successfully.
	// Automatically completes the previous step with its completion message if one exists.
	Start(inProgress, completed string)

	// Complete marks the current step as successfully completed using its completion message.
	// Typically called with defer to complete the last step.
	Complete()

	// Fail marks the current step as failed with the given error.
	// After failure, the step logger will not auto-complete on the next Start().
	Fail(err error)
}

StepLogger provides an interface for logging operational steps. Implementations can display steps differently based on output mode (text vs JSON).

The Start() method takes two messages: one for in-progress state and one for completion. It automatically completes the previous step with its completion message before starting a new one. The Complete() method should be called with defer to complete the last step. The Fail() method marks the current step as failed.

func FromContext

func FromContext(ctx context.Context) StepLogger

FromContext retrieves the logger from context. Returns a NoOpLogger if no logger is in context.

func NewNoOpLogger

func NewNoOpLogger() StepLogger

NewNoOpLogger creates a new no-op step logger.

func NewTextLogger

func NewTextLogger(w io.Writer) StepLogger

NewTextLogger creates a new text step logger that outputs to the given writer.

Jump to

Keyboard shortcuts

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