conslogging

package
v0.8.19 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2026 License: MPL-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package conslogging provides specialized console logging implementations, including colorized output, buffered logging, and progress reporting for earth builds.

Index

Constants

View Source
const (
	// NoPadding means the old behavior of printing the full target only.
	NoPadding int = -1
	// DefaultPadding always prints 20 characters for the target, right
	// justified. If it is longer, it prints the right 20 characters.
	DefaultPadding int = 20
)
View Source
const (
	// StatusWaiting is the status for a target that has yet to execute.
	StatusWaiting = "waiting"

	// StatusInProgress is the status for a target that is currently executing.
	StatusInProgress = "in_progress"

	// StatusComplete is the status for a target that has run to completion.
	StatusComplete = "complete"

	// StatusCancelled is the status for a target that did not run to completion, and was interrupted.
	StatusCancelled = "cancelled"

	// ResultSuccess is the result for a target that exits successfully.
	ResultSuccess = "success"

	// ResultFailure is the result for a target that exited with some kind of error code.
	ResultFailure = "failure"

	// ResultCancelled is the results for a target that did not run to completion.
	ResultCancelled = "cancelled"
)

These types are also used by our log server, too.

Variables

This section is empty.

Functions

This section is empty.

Types

type BufferedLogger

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

BufferedLogger is a logger that queues up messages until Flush is called.

func NewBufferedLogger

func NewBufferedLogger(cl *ConsoleLogger) *BufferedLogger

NewBufferedLogger creates a new BufferedLogger.

func (*BufferedLogger) Flush

func (bl *BufferedLogger) Flush()

Flush prints the queued up messages to the underlying console.

func (*BufferedLogger) Printf

func (bl *BufferedLogger) Printf(format string, v ...any)

Printf prints a formatted string to the delayed console.

type ConsoleLogger

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

ConsoleLogger is a writer for consoles.

func Current

func Current(prefixPadding int, logLevel LogLevel, githubAnnotations bool) *ConsoleLogger

Current returns the current console.

func New

func New(
	w io.Writer, mu *sync.Mutex, prefixPadding int, logLevel LogLevel, githubAnnotations bool,
) *ConsoleLogger

New returns a new ConsoleLogger with a predefined target writer.

func (*ConsoleLogger) ColorPrint

func (l *ConsoleLogger) ColorPrint(c *color.Color, msg string)

ColorPrint prints message to the console in a specific color.

func (*ConsoleLogger) ColorPrintf

func (l *ConsoleLogger) ColorPrintf(c *color.Color, format string, args ...any)

ColorPrintf prints formatted message to the console in a specific color.

func (*ConsoleLogger) DebugBytes

func (l *ConsoleLogger) DebugBytes(data []byte)

DebugBytes prints bytes directly to the console when debug flag is set.

func (*ConsoleLogger) DebugPrintf

func (l *ConsoleLogger) DebugPrintf(format string, args ...any)

DebugPrintf prints formatted message to the console when debug flag is set.

func (*ConsoleLogger) HelpPrint

func (l *ConsoleLogger) HelpPrint(msg string)

HelpPrint prints message to the console with `Help:` prefix in a specific color.

func (*ConsoleLogger) HelpPrintf

func (l *ConsoleLogger) HelpPrintf(format string, args ...any)

HelpPrintf prints formatted message to the console with `Help:` prefix in a specific color.

func (*ConsoleLogger) Prefix

func (l *ConsoleLogger) Prefix() string

Prefix returns the console's prefix.

func (*ConsoleLogger) PrefixColor

func (l *ConsoleLogger) PrefixColor() *color.Color

PrefixColor returns the color used for the prefix.

func (*ConsoleLogger) Print

func (l *ConsoleLogger) Print(msg string)

Print prints message to the console.

func (*ConsoleLogger) PrintBar

func (l *ConsoleLogger) PrintBar(c *color.Color, msg, phase string)

PrintBar prints an earth message bar.

func (*ConsoleLogger) PrintBytes

func (l *ConsoleLogger) PrintBytes(data []byte)

PrintBytes prints bytes directly to the console.

func (*ConsoleLogger) PrintFailure

func (l *ConsoleLogger) PrintFailure(phase string)

PrintFailure prints the failure message.

func (*ConsoleLogger) PrintGHAError

func (l *ConsoleLogger) PrintGHAError(message string, fns ...GHAErrorOpt)

PrintGHAError constructs a GitHub Actions error message.

func (*ConsoleLogger) PrintGHASummary

func (l *ConsoleLogger) PrintGHASummary(message string)

PrintGHASummary prints a GitHub Actions summary message to GITHUB_STEP_SUMMARY.

func (*ConsoleLogger) PrintPhaseFooter

func (l *ConsoleLogger) PrintPhaseFooter(phase string)

PrintPhaseFooter prints the phase footer.

func (*ConsoleLogger) PrintPhaseHeader

func (l *ConsoleLogger) PrintPhaseHeader(phase string, disabled bool, special string)

PrintPhaseHeader prints the phase header.

func (*ConsoleLogger) PrintSuccess

func (l *ConsoleLogger) PrintSuccess()

PrintSuccess prints the success message.

func (*ConsoleLogger) Printf

func (l *ConsoleLogger) Printf(format string, args ...any)

Printf prints formatted message to the console.

func (*ConsoleLogger) Salt

func (l *ConsoleLogger) Salt() string

Salt returns the console's salt.

func (*ConsoleLogger) VerboseBytes

func (l *ConsoleLogger) VerboseBytes(data []byte)

VerboseBytes prints bytes directly to the console when verbose flag is set.

func (*ConsoleLogger) VerbosePrint

func (l *ConsoleLogger) VerbosePrint(msg string)

VerbosePrint prints a message to the console when verbose flag is set.

func (*ConsoleLogger) VerbosePrintf

func (l *ConsoleLogger) VerbosePrintf(format string, args ...any)

VerbosePrintf prints formatted message to the console when verbose flag is set.

func (*ConsoleLogger) VerboseWarn

func (l *ConsoleLogger) VerboseWarn(msg string)

VerboseWarn prints a message in red to errWriter when verbose flag is set.

func (*ConsoleLogger) VerboseWarnf

func (l *ConsoleLogger) VerboseWarnf(format string, args ...any)

VerboseWarnf prints a formatted message in red to errWriter when verbose flag is set.

func (*ConsoleLogger) Warn

func (l *ConsoleLogger) Warn(message string)

Warn prints a warning message in red to errWriter.

func (*ConsoleLogger) Warnf

func (l *ConsoleLogger) Warnf(format string, args ...any)

Warnf prints a formatted warning message in red to errWriter.

func (*ConsoleLogger) WithCached

func (l *ConsoleLogger) WithCached(isCached bool) *ConsoleLogger

WithCached returns a ConsoleLogger with isCached flag set accordingly.

func (*ConsoleLogger) WithFailed

func (l *ConsoleLogger) WithFailed(isFailed bool) *ConsoleLogger

WithFailed returns a ConsoleLogger with isFailed flag set accordingly.

func (*ConsoleLogger) WithLocal

func (l *ConsoleLogger) WithLocal(isLocal bool) *ConsoleLogger

WithLocal returns a ConsoleLogger with local set.

func (*ConsoleLogger) WithLogLevel

func (l *ConsoleLogger) WithLogLevel(logLevel LogLevel) *ConsoleLogger

WithLogLevel changes the log level.

func (*ConsoleLogger) WithMetadataMode

func (l *ConsoleLogger) WithMetadataMode(metadataMode bool) *ConsoleLogger

WithMetadataMode returns a ConsoleLogger with metadata printing mode set.

func (*ConsoleLogger) WithPrefix

func (l *ConsoleLogger) WithPrefix(prefix string) *ConsoleLogger

WithPrefix returns a ConsoleLogger with a prefix added.

func (*ConsoleLogger) WithPrefixAndSalt

func (l *ConsoleLogger) WithPrefixAndSalt(prefix string, salt string) *ConsoleLogger

WithPrefixAndSalt returns a ConsoleLogger with a prefix and a seed added.

func (*ConsoleLogger) WithPrefixWriter

func (l *ConsoleLogger) WithPrefixWriter(w PrefixWriter) *ConsoleLogger

WithPrefixWriter returns a ConsoleLogger with a prefix writer.

func (*ConsoleLogger) WithWriter

func (l *ConsoleLogger) WithWriter(w io.Writer) *ConsoleLogger

WithWriter returns a ConsoleLogger with stderr pointed at the provided io.Writer.

type GHAError

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

GHAError represents a GitHub Actions error with formatted output.

func (*GHAError) FormattedMessage

func (e *GHAError) FormattedMessage() string

FormattedMessage returns the formatted message for the GHAError.

type GHAErrorOpt

type GHAErrorOpt func(*GHAError)

GHAErrorOpt is a functional option for configuring a GHAError.

func WithGHASourceLocation

func WithGHASourceLocation(file string, line, col int32) GHAErrorOpt

WithGHASourceLocation specifies the source location file, line, and column for a GHAError.

type LogLevel

type LogLevel int

LogLevel defines which types of log messages are displayed (e.g. warning, info, verbose).

const (
	// Silent silences logging.
	Silent LogLevel = iota
	// Warn only display warning log messages.
	Warn
	// Info displays info and higher priority log messages.
	Info
	// Verbose displays verbose and higher priority log messages.
	Verbose
	// Debug displays all log messages.
	Debug
)

type Manifest

type Manifest struct {
	CreatedAt  time.Time        `json:"created_at"`
	Status     string           `json:"status"`
	Result     string           `json:"result"`
	Entrypoint string           `json:"entrypoint"`
	Targets    []TargetManifest `json:"targets"`
	Version    int              `json:"version"`
	Duration   int              `json:"duration"`
}

Manifest is the structure for the log bundle manifest, including all overarching data we need.

type Permissions

type Permissions struct {
	Users   []string `json:"users"`
	Orgs    []string `json:"orgs"`
	Version int      `json:"version"`
}

Permissions is the structure for the permissions manifest that can grant view rights to other earth users.

type PrefixFormatter added in v0.8.18

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

PrefixFormatter is a formatter for log output.

func NewPrefixFormatter

func NewPrefixFormatter(formatOpt ...formatOpt) *PrefixFormatter

NewPrefixFormatter creates a new prefix formatter for log output.

func (*PrefixFormatter) Format added in v0.8.18

func (pb *PrefixFormatter) Format(prefix string, padding int) (modifiedPrefix string)

Format returns a formatted prefix.

type PrefixWriter

type PrefixWriter interface {
	io.Writer
	// WithPrefix returns a new PrefixWriter with the given prefix.
	WithPrefix(prefix string) PrefixWriter
}

PrefixWriter is a writer that can take a prefix.

type TargetManifest

type TargetManifest struct {
	Name     string `json:"name"`
	Status   string `json:"status"`
	Result   string `json:"result"`
	Command  string `json:"command,omitempty"`
	Summary  string `json:"summary,omitempty"`
	Duration int    `json:"duration"`
	Size     int    `json:"size"`
}

TargetManifest is the structure for an individual target, indicating all relevant information.

Jump to

Keyboard shortcuts

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