log

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2023 License: MPL-2.0 Imports: 4 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithLogger

func WithLogger(ctx context.Context, l Leveler) context.Context

WithLogger returns a child context.Context with l attached.

Types

type Author

type Author interface {
	// We cover some methods to add fields to the log message, here. We don't
	// want to cover every possible type, but some of the more common types are
	// provided. Log performance is not nearly as critical in an editor as it is
	// in server applications, so some amount of wasted type conversion and
	// extra allocation is reasonable, but we do want to make use of _some_ of
	// the advantages we get from using a zero-allocation logger under the
	// covers.
	Str(k, v string) Author
	Int(k string, v int) Author
	Float64(k string, v float64) Author
	Error(k string, v error) Author
	Dur(k string, d time.Duration) Author
	Stringer(k string, v fmt.Stringer) Author
	Interface(k string, v any) Author

	// Err(err) is sugar for Error("error", err)
	Err(error) Author

	// Msgf performs the write with a message included to provide some final
	// context after adding detail with the above methods.
	Msgf(string, ...any)
}

Author is the type that actually constructs and writes a log message.

type Leveler

type Leveler interface {
	Debug() Author
	Info() Author
	Warn() Author
	Error() Author

	// Err(err) is sugar for Error().Err(err)
	Err(error) Author
}

Leveler represents a logging type that vidar can pass to plugins, to provide more consistent logging between vidar and third party tools.

Plugins should prefer to write UI messages (via the 'inform' operation) so that users can see the full detail; but sometimes, the detail is too excessive to show in a UI monolog. In those cases, the excessive detail may be logged to this logger and the UI message may inform the user that detail was added to vidar's log output.

func FromCtx

func FromCtx(ctx context.Context) Leveler

FromCtx returns a Leveler loaded from ctx (as set by WithLogger). It panics if no logger is found.

The first thing that vidar does after attaching preferences to the root context is attach a logger, so a logger should always be present in all contexts.

Jump to

Keyboard shortcuts

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