log

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDetails

func GetDetails(err error) []any

func Smprintf

func Smprintf(f string, args ...any) string

func WithDetails

func WithDetails(err error, args ...any) error

Types

type ActionFlag

type ActionFlag string

ActionFlag provides additional flags for actions

const (
	// None is not a flag.
	None ActionFlag = "none"

	// Spinning requests a manually ticked spinner.
	Spinning ActionFlag = "spin"

	// AutoSpinning requests an automatically ticked spinner.
	AutoSpinning ActionFlag = "auto-spin"

	// Plain requests that the log line be printed without spinners, outcomes,
	// etc. Just the message itself.
	Plain ActionFlag = "plain"
)

type DetailedError

type DetailedError interface {
	Details() []any
}

type Interface

type Interface interface {
	Debug(line string, fields ...any)
	Info(line string, fields ...any)
	Warn(line string, fields ...any)
	Error(line string, fields ...any)
	Err(err error, fields ...any)

	With(args ...any) Interface

	StartAction(key, desc string, flags ...ActionFlag)
	TickAction(key string)
	MarkAction(key string, outcome Outcome)

	Output(level Level) io.Writer
}

Interface is the logging interface that is provided to both the plugin logging system and the master logging system.

type Level

type Level int
const (
	LevelDebug Level = iota
	LevelInfo
	LevelWarn
	LevelError
)

type Logger

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

Logger is provided to plugins to allow them to interact with the parent task in a standard way. Other language implementations can mimic the behavior here to achieve the same results. Under the hood is just a structured logging system passing information back to the master process via tagged values.

func New

func New(log LowLevelLogger) *Logger

New creates a new logger for use with a plugin.

func (*Logger) Debug

func (l *Logger) Debug(fmt string, args ...any)

Debug logs the given debug log.

func (*Logger) Err

func (l *Logger) Err(err error, args ...any)

Err logs the given error as an error log. It will add any details attached to the log (via the log.WithDetails interface) as additional arguments.

func (*Logger) Error

func (l *Logger) Error(fmt string, args ...any)

Error logs the given error log.

func (*Logger) Info

func (l *Logger) Info(fmt string, args ...any)

Info logs the given info log.

func (*Logger) MarkAction

func (l *Logger) MarkAction(key string, outcome Outcome)

MarkAction logs the original message with the given outcome.

func (*Logger) Output

func (l *Logger) Output(level Level) io.Writer

Output returns an io.Writer that can be used to write to the given log level.

func (*Logger) StartAction

func (l *Logger) StartAction(key, desc string, flags ...ActionFlag)

StartAction logs the given message, but marks the action as being a progress item that has a followup. You may pass zero or more ActionFlags to mark this action as having additional features. Currently, flags include:

log.None - no-op flag
log.Spin - request a manually ticked spinner
log.AutoSpin - request an automatically ticked spinner
log.Plain - just the message, no spinners, outcomes, etc.

func (*Logger) TickAction

func (l *Logger) TickAction(key string)

TickAction logs the original message again, but is intended to be used to make a spinner move a tick.

func (*Logger) Warn

func (l *Logger) Warn(fmt string, args ...any)

Warn logs the given warning log.

func (*Logger) With

func (l *Logger) With(args ...any) Interface

With returns a new logger with the given args included with every log sent.

type LowLevelLogger

type LowLevelLogger interface {
	Debug(line string, fields ...any)
	Info(line string, fields ...any)
	Warn(line string, fields ...any)
	Error(line string, fields ...any)
}

type Outcome

type Outcome string

Outcome is used to record the outcome of some running action.

const (
	Working Outcome = ""
	Fail    Outcome = "fail"
	Pass    Outcome = "pass"
	Skip    Outcome = "skip"
	Retry   Outcome = "retry"
)

func (Outcome) IsFinal

func (o Outcome) IsFinal() bool

IsFinal returns true if the Outcome is considered a terminal state.

Jump to

Keyboard shortcuts

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