console

package
v0.7.1-pre2 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2024 License: Unlicense Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LogWriter

func LogWriter(l LogPrinter) io.Writer

LogWriter wraps up l in an io.Writer to be used for console logging.

Types

type LogPrinter

type LogPrinter interface {
	Log(...any)
}

LogPrinter is a type which has a Log method. The main example is testing.T.

type Logger

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

Logger is a type which may be used to write logs to a console.

func FromCtx

func FromCtx(c context.Context) *Logger

FromCtx retrieves a Logger from c.

func NewLogger

func NewLogger(w io.Writer, opts ...Opt) *Logger

NewLogger constructs a Logger to write to w.

func (*Logger) Ctx

func (l *Logger) Ctx(c context.Context) context.Context

Ctx returns a child context.Context with l set as the context's logger.

func (*Logger) Print

func (l *Logger) Print(output string, opts ...PrintOption) error

Print prints a line of output to the console.

func (*Logger) WithPrefix

func (l *Logger) WithPrefix(pfx string) *Logger

WithPrefix returns a new Logger with pfx added. Any existing prefix in l will be prepended.

type Opt

type Opt func(*Logger)

func Verbose

func Verbose() Opt

type PrintOption added in v0.7.0

type PrintOption func(printPrefs) printPrefs

func AsVerbose added in v0.7.0

func AsVerbose() PrintOption

AsVerbose marks the message as a verbose message, only printing if the console logger is in verbose mode.

func Fmt added in v0.7.0

func Fmt(args ...any) PrintOption

Fmt adds format args to the print statement.

func NewlinePfx added in v0.7.0

func NewlinePfx() PrintOption

NewlinePfx changes the message to _start_ with a newline, rather than end with one. Loggers usually end every message with a newline. This moves the newline to the start.

func Once added in v0.7.0

func Once() PrintOption

Once ensures that this message is only printed once. This is useful for messages that might get repeated by multiple goroutines.

Jump to

Keyboard shortcuts

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