output

package
v1.25.3 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// UserOut is the customized logrus log used for direct user output
	UserOut = func() *log.Logger {
		l := log.New()
		l.SetOutput(os.Stdout)
		logLevel := log.InfoLevel
		if nodeps.IsEnvTrue("DDEV_DEBUG") || nodeps.IsEnvTrue("DDEV_VERBOSE") {
			logLevel = log.DebugLevel
		}
		l.SetLevel(logLevel)
		log.SetLevel(logLevel)
		if JSONOutput {
			l.SetFormatter(DdevOutputJSONFormatter)
			log.SetFormatter(DdevOutputJSONFormatter)
		} else {
			l.SetFormatter(DdevOutputFormatter)
			log.SetFormatter(DdevOutputFormatter)
		}
		return l
	}()
	// UserErr is the customized logrus log used for direct user stderr
	UserErr = func() *log.Logger {
		l := log.New()
		l.SetOutput(&ErrorWriter{})
		if JSONOutput {
			l.SetFormatter(DdevOutputJSONFormatter)
		} else {
			l.SetFormatter(DdevOutputFormatter)
		}
		return l
	}()
	// DdevOutputFormatter is the specialized formatter for UserOut
	DdevOutputFormatter = &TextFormatter{
		DisableColors:    !ColorsEnabled(),
		DisableTimestamp: true,
	}
	// DdevOutputJSONFormatter is the specialized JSON formatter for UserOut
	DdevOutputJSONFormatter = &log.JSONFormatter{}
	// JSONOutput indicates if JSON output mode is enabled, determined by command-line flags.
	// Parsed early, prior to Cobra flag initialization, to configure logging correctly from start.
	// Manual parsing is necessary because Cobra registers flags too late for this early use.
	JSONOutput = ParseBoolFlag("json-output", "j")
)
View Source
var HasTermHyperlinks = sync.OnceValue(func() bool {
	return detectHyperlinks(
		os.Getenv("FORCE_HYPERLINK"),
		!JSONOutput && isatty.IsTerminal(os.Stdout.Fd()),
		os.Getenv("TERM_PROGRAM"),
		os.Getenv("VTE_VERSION"),
		os.Getenv("WT_SESSION"),
		os.Getenv("KONSOLE_VERSION"),
		os.Getenv("TERM"),
	)
})

HasTermHyperlinks reports whether the terminal likely renders OSC 8 hyperlinks. Terminals that don't support OSC 8 are expected to silently ignore the escape sequences, but detection avoids emitting them where they are known to misbehave (e.g. GNU screen) or are useless (pipes). FORCE_HYPERLINK=1/0 overrides detection, following the convention used by eza, lsd, and the chalk/supports-hyperlinks ecosystem.

Functions

func ColorsEnabled added in v1.24.7

func ColorsEnabled() bool

ColorsEnabled returns true if colored output is enabled Implementation from https://no-color.org/

func FileURL added in v1.25.3

func FileURL(path string) string

FileURL converts an absolute filesystem path into a file:// URL usable as an OSC 8 hyperlink target, e.g. to open a project directory.

func Hyperlink(targetURL string, linkText string) string

Hyperlink returns linkText wrapped in an OSC 8 terminal hyperlink pointing at targetURL when the terminal supports it; otherwise it returns linkText unchanged. The link target is invisible, so linkText may later be truncated for display while the full targetURL remains clickable.

func ParseBoolFlag added in v1.24.7

func ParseBoolFlag(long string, short string) bool

ParseBoolFlag scans os.Args backward to apply last-occurrence precedence for a boolean flag. Handles both --long[=true|false] and -s[=true|false] forms. Treats short flag in combined group (e.g. -xj) as implicit true. Returns false if the flag is absent or its value is invalid. Disabled entirely when running under `go test`.

Types

type ErrorWriter added in v1.21.5

type ErrorWriter struct{}

ErrorWriter allows writing stderr Splitting to stderr approach from https://huynvk.dev/blog/4-tips-for-logging-on-gcp-using-golang-and-logrus

func (*ErrorWriter) Write added in v1.21.5

func (w *ErrorWriter) Write(p []byte) (n int, err error)

type Fields added in v1.24.7

type Fields = log.Fields

type JSONProgressWriter added in v1.25.3

type JSONProgressWriter struct{}

JSONProgressWriter is an io.Writer that routes each write through UserErr.Info so compose progress lines are formatted by the active logrus formatter (e.g. JSON) instead of being written as raw text.

func (*JSONProgressWriter) Write added in v1.25.3

func (w *JSONProgressWriter) Write(p []byte) (int, error)

type TextFormatter

type TextFormatter struct {
	// Set to true to bypass checking for a TTY before outputting colors.
	ForceColors bool

	// Force disabling colors.
	DisableColors bool

	// Disable timestamp logging. useful when output is redirected to logging
	// system that already adds timestamps.
	DisableTimestamp bool

	// Enable logging the full timestamp when a TTY is attached instead of
	// the time passed since beginning of execution.
	FullTimestamp bool

	// TimestampFormat to use for display when a full timestamp is printed
	TimestampFormat string

	// The fields are sorted by default for a consistent output. For applications
	// that log extremely frequently and don't use the JSON formatter this may not
	// be desired.
	DisableSorting bool

	// QuoteEmptyFields will wrap empty fields in quotes if true
	QuoteEmptyFields bool

	sync.Once
	// contains filtered or unexported fields
}

TextFormatter formats logs into text. This is a specialization of https://github.com/sirupsen/logrus/blob/master/text_formatter.go It's intended to be used for all user-oriented output from DDEV

func (*TextFormatter) Format

func (f *TextFormatter) Format(entry *log.Entry) ([]byte, error)

Format renders a single log entry. A key named "raw" is discarded here as it's for json consumption.

type WaitTimer added in v1.25.0

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

WaitTimer tracks elapsed time for wait operations with inline output

func StartWait added in v1.25.0

func StartWait(message string) *WaitTimer

StartWait prints a waiting message (without newline) and returns a WaitTimer to track elapsed time. Call Complete() when the operation finishes. In JSON mode, no message is printed.

func (*WaitTimer) Complete added in v1.25.0

func (w *WaitTimer) Complete(err error) time.Duration

Complete prints the elapsed time on the same line as the wait message. If err is non-nil, just prints a newline.

Jump to

Keyboard shortcuts

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