logger

package
v0.33.21 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const FieldNameBuildEvent = "buildEvent"
View Source
const FieldNameProgressID = "progressID"
View Source
const FieldNameProgressMustPrint = "progressMustPrint"

Most progress lines are optional. For example, if a bunch of little upload updates come in, it's ok to skip some.

progressMustPrint="1" indicates that this line must appear in the output - e.g., a line that communicates that the upload finished.

Variables

View Source
var (
	NoneLvl    = Level{/* contains filtered or unexported fields */}
	DebugLvl   = Level{/* contains filtered or unexported fields */}
	VerboseLvl = Level{/* contains filtered or unexported fields */}
	InfoLvl    = Level{/* contains filtered or unexported fields */}
	WarnLvl    = Level{/* contains filtered or unexported fields */}
	ErrorLvl   = Level{/* contains filtered or unexported fields */}
)
View Source
var LoggerContextKey = contextKey{}

Functions

func Blue

func Blue(l Logger) *color.Color

func CtxWithForkedOutput

func CtxWithForkedOutput(ctx context.Context, writer io.Writer) context.Context

Returns a context containing a logger that forks all of its output to both the parent context's logger and to the given `io.Writer`

func CtxWithLogHandler added in v0.10.25

func CtxWithLogHandler(ctx context.Context, handler LogHandler) context.Context

func DefaultEnv added in v0.18.3

func DefaultEnv(ctx context.Context) []string

DefaultEnv returns a set of strings in the form of "key=value" based on the current process' environment with additional entries to improve subprocess log output.

func Green

func Green(l Logger) *color.Color

func NewPrefixedLogger added in v0.14.0

func NewPrefixedLogger(prefix string, original Logger) *prefixedLogger

func PrepareEnv added in v0.18.5

func PrepareEnv(l Logger, env []string) []string

PrepareEnv returns a set of strings in the form of "key=value" based on a provided set of strings in the same format with additional entries to improve subprocess log output.

func Red

func Red(l Logger) *color.Color

func WithLogger

func WithLogger(ctx context.Context, logger Logger) context.Context

func Yellow

func Yellow(l Logger) *color.Color

Types

type DeferredLogger

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

A logger that buffers its log lines until we have an output logger.

func NewDeferredLogger

func NewDeferredLogger(ctx context.Context) *DeferredLogger

func (*DeferredLogger) CopyBuffered added in v0.15.0

func (dl *DeferredLogger) CopyBuffered(lvl Level) *bytes.Buffer

func (*DeferredLogger) Original

func (dl *DeferredLogger) Original() Logger

The original logger that we're deferring output away from.

func (*DeferredLogger) SetOutput

func (dl *DeferredLogger) SetOutput(l Logger)

Set the output logger, and send all the buffered output to the new logger.

type Fields added in v0.14.0

type Fields map[string]string

Allow arbitrary fields on a log. Inspired by the logrus.Fields API https://github.com/sirupsen/logrus

type FuncLoggerWriter

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

func (FuncLoggerWriter) Write

func (fw FuncLoggerWriter) Write(b []byte) (int, error)

type Level

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

func (Level) AsSevereAs added in v0.14.0

func (l Level) AsSevereAs(log Level) bool

func (Level) ShouldDisplay added in v0.14.0

func (l Level) ShouldDisplay(log Level) bool

If l is the logger level, determine if we should display logs of the given severity.

func (Level) ToProtoID added in v0.14.0

func (l Level) ToProtoID() int32

type LogHandler added in v0.10.25

type LogHandler interface {
	Write(level Level, fields Fields, bytes []byte) error
}

type Logger

type Logger interface {
	// log information that is likely to only be of interest to tilt developers
	Debugf(format string, a ...interface{})

	// log information that a tilt user might not want to see on every run, but that they might find
	// useful when debugging their Tiltfile/docker/k8s configs
	Verbosef(format string, a ...interface{})

	// log information that we always want to show
	Infof(format string, a ...interface{})

	// Warnings to show in the alert pane.
	Warnf(format string, a ...interface{})

	// Halting errors to show in the alert pane.
	Errorf(format string, a ...interface{})

	Write(level Level, bytes []byte)

	// gets an io.Writer that filters to the specified level for, e.g., passing to a subprocess
	Writer(level Level) io.Writer

	Level() Level

	SupportsColor() bool

	WithFields(fields Fields) Logger
}

Logger with better controls for levels and colors.

Note that our loggers often serve as both traditional loggers (where each call to PodLog() is a discrete log entry that may be emitted as JSON or with newlines) and as Writers (where each call to Write() may be part of a larger output stream, and each message may not end in a newline).

Logger implementations that bridge these two worlds should have discrete messages (like Infof) append a newline to the string before passing it to Write().

func Get

func Get(ctx context.Context) Logger

func NewFuncLogger

func NewFuncLogger(supportsColor bool, level Level, write func(level Level, fields Fields, b []byte) error) Logger

func NewLogger

func NewLogger(minLevel Level, writer io.Writer) Logger

func NewTestLogger added in v0.20.4

func NewTestLogger(writer io.Writer) Logger

type MutexWriter added in v0.14.0

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

func NewMutexWriter added in v0.14.0

func NewMutexWriter(underlying io.Writer) MutexWriter

func (MutexWriter) Write added in v0.14.0

func (w MutexWriter) Write(b []byte) (int, error)

Jump to

Keyboard shortcuts

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