conslogging

package
v0.8.17 Latest Latest
Warning

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

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

Documentation

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

func NewPrefixFormatter

func NewPrefixFormatter(formatOpt ...formatOpt) *prefixFormatter

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 ColorMode

type ColorMode int

ColorMode is the mode in which colors are represented in the output.

const (
	// AutoColor automatically detects the presence of a TTY to decide if
	// color should be used.
	AutoColor ColorMode = iota
	// NoColor disables use of color.
	NoColor
	// ForceColor forces use of color.
	ForceColor
)

type ConsoleLogger

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

ConsoleLogger is a writer for consoles.

func Current

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

Current returns the current console.

func New

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

New returns a new ConsoleLogger with a predefined target writer.

func (ConsoleLogger) ColorPrint

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

ColorPrint prints message to the console in a specific color.

func (ConsoleLogger) ColorPrintf

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

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

func (ConsoleLogger) DebugBytes

func (cl ConsoleLogger) DebugBytes(data []byte)

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

func (ConsoleLogger) DebugPrintf

func (cl ConsoleLogger) DebugPrintf(format string, args ...any)

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

func (ConsoleLogger) HelpPrint

func (cl ConsoleLogger) HelpPrint(msg string)

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

func (ConsoleLogger) HelpPrintf

func (cl ConsoleLogger) HelpPrintf(format string, args ...any)

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

func (ConsoleLogger) Prefix

func (cl ConsoleLogger) Prefix() string

Prefix returns the console's prefix.

func (ConsoleLogger) PrefixColor

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

PrefixColor returns the color used for the prefix.

func (ConsoleLogger) Print

func (cl ConsoleLogger) Print(msg string)

Print prints message to the console.

func (ConsoleLogger) PrintBar

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

PrintBar prints an earthly message bar.

func (ConsoleLogger) PrintBytes

func (cl ConsoleLogger) PrintBytes(data []byte)

PrintBytes prints bytes directly to the console.

func (ConsoleLogger) PrintFailure

func (cl ConsoleLogger) PrintFailure(phase string)

PrintFailure prints the failure message.

func (*ConsoleLogger) PrintGHAError

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

PrintGHAError constructs a GitHub Actions error message.

func (*ConsoleLogger) PrintGHASummary

func (cl *ConsoleLogger) PrintGHASummary(message string)

PrintGHASummary prints a GitHub Actions summary message to GITHUB_STEP_SUMMARY.

func (ConsoleLogger) PrintPhaseFooter

func (cl ConsoleLogger) PrintPhaseFooter(phase string, disabled bool, special string)

PrintPhaseFooter prints the phase footer.

func (ConsoleLogger) PrintPhaseHeader

func (cl ConsoleLogger) PrintPhaseHeader(phase string, disabled bool, special string)

PrintPhaseHeader prints the phase header.

func (ConsoleLogger) PrintSuccess

func (cl ConsoleLogger) PrintSuccess()

PrintSuccess prints the success message.

func (ConsoleLogger) Printf

func (cl ConsoleLogger) Printf(format string, args ...any)

Printf prints formatted message to the console.

func (ConsoleLogger) Salt

func (cl ConsoleLogger) Salt() string

Salt returns the console's salt.

func (ConsoleLogger) VerboseBytes

func (cl ConsoleLogger) VerboseBytes(data []byte)

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

func (ConsoleLogger) VerbosePrint

func (cl ConsoleLogger) VerbosePrint(msg string)

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

func (ConsoleLogger) VerbosePrintf

func (cl ConsoleLogger) VerbosePrintf(format string, args ...any)

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

func (ConsoleLogger) VerboseWarn

func (cl ConsoleLogger) VerboseWarn(msg string)

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

func (ConsoleLogger) VerboseWarnf

func (cl ConsoleLogger) VerboseWarnf(format string, args ...any)

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

func (ConsoleLogger) Warn

func (cl ConsoleLogger) Warn(message string)

Warn prints a warning message in red to errWriter.

func (ConsoleLogger) Warnf

func (cl ConsoleLogger) Warnf(format string, args ...any)

Warnf prints a formatted warning message in red to errWriter.

func (ConsoleLogger) WithCached

func (cl ConsoleLogger) WithCached(isCached bool) ConsoleLogger

WithCached returns a ConsoleLogger with isCached flag set accordingly.

func (ConsoleLogger) WithFailed

func (cl ConsoleLogger) WithFailed(isFailed bool) ConsoleLogger

WithFailed returns a ConsoleLogger with isFailed flag set accordingly.

func (ConsoleLogger) WithLocal

func (cl ConsoleLogger) WithLocal(isLocal bool) ConsoleLogger

WithLocal returns a ConsoleLogger with local set.

func (ConsoleLogger) WithLogLevel

func (cl ConsoleLogger) WithLogLevel(logLevel LogLevel) ConsoleLogger

WithLogLevel changes the log level.

func (ConsoleLogger) WithMetadataMode

func (cl ConsoleLogger) WithMetadataMode(metadataMode bool) ConsoleLogger

WithMetadataMode returns a ConsoleLogger with metadata printing mode set.

func (ConsoleLogger) WithPrefix

func (cl ConsoleLogger) WithPrefix(prefix string) ConsoleLogger

WithPrefix returns a ConsoleLogger with a prefix added.

func (ConsoleLogger) WithPrefixAndSalt

func (cl ConsoleLogger) WithPrefixAndSalt(prefix string, salt string) ConsoleLogger

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

func (ConsoleLogger) WithPrefixWriter

func (cl ConsoleLogger) WithPrefixWriter(w PrefixWriter) ConsoleLogger

WithPrefixWriter returns a ConsoleLogger with a prefix writer.

func (ConsoleLogger) WithWriter

func (cl 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
}

func (*GHAError) FormattedMessage

func (e *GHAError) FormattedMessage() string

type GHAErrorOpt

type GHAErrorOpt func(*GHAError)

func WithGHASourceLocation

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

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 Earthly users.

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