logging

package
v0.0.0-...-d046166 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2020 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package logging is used by the tast executable to write informational output.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewContext

func NewContext(ctx context.Context, lg Logger) context.Context

NewContext returns a new context derived from ctx that carries value lg.

Types

type Logger

type Logger interface {
	// Close deinitializes the logger, returning the terminal to its original state (if necessary).
	Close() error

	// Log formats args using default formatting and logs them unconditionally and permanently (i.e.
	// the message will remain in the terminal's scrollback buffer).
	Log(args ...interface{})
	// Logf is similar to Log but formats args as per fmt.Sprintf.
	Logf(format string, args ...interface{})

	// Debug formats args using default formatting and prints a message that may be omitted in
	// non-verbose modes or only displayed onscreen for a short period of time.
	Debug(args ...interface{})
	// Debugf is similar to Debug but formats args as per fmt.Sprintf.
	Debugf(format string, args ...interface{})

	// Status updates a transient status message describing the current state of execution. Some
	// implementations may not display these messages.
	Status(msg string)

	// AddWriter adds an additional writer to which Log, Logf, Debug, and Debugf's messages are
	// logged (regardless of any verbosity settings).
	// flag contains logging properties to be passed to log.New.
	// An error is returned if w has already been added.
	AddWriter(w io.Writer, flag int) error
	// RemoveWriter stops logging to a writer previously passed to AddWriter.
	// An error is returned if w was not previously added.
	RemoveWriter(w io.Writer) error
}

Logger is the interface used for logging by the tast executable.

func FromContext

func FromContext(ctx context.Context) (Logger, bool)

FromContext returns the Logger value stored in ctx, if any.

func NewDiscard

func NewDiscard() Logger

NewDiscard is a convencience function that returns a Logger that discards all messages.

func NewFancy

func NewFancy(lines int) (Logger, error)

NewFancy returns an implementation of the Logger interface that renders messages onscreen using ANSI escape codes to create multiple scrolling regions (e.g. a limited number of debug messages remain onscreen).

func NewSimple

func NewSimple(w io.Writer, flag int, verbose bool) Logger

NewSimple returns an object implementing the Logger interface to perform simple logging to w. flag contains logging properties to be passed to log.New. If verbose is true, all messages will be logged to w; otherwise, only non-debug messages will be logged to w.

Jump to

Keyboard shortcuts

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