log

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Default = New()
View Source
var Env = "TESTKIT_LOG"

Env is the default name of the environment variable that contains the log entries.

Functions

func E

func E(l *Leveled, name string, severity Level, e error)

E prints the error at the specified severity using the leveled logger l.

Similarly to log.Leveled is, this is intended for use in the library code, rather than the application code. An application should use Logger.E instead.

Types

type L

type L struct {
	Logger
}

func (*L) Debugf

func (l *L) Debugf(format string, a ...interface{})

func (*L) Errorf

func (l *L) Errorf(format string, a ...interface{})

func (*L) Infof

func (l *L) Infof(format string, a ...interface{})

type Level

type Level int8

Level is enum for log levels.

The larger the value, the more verbose the log. For example, if you want to print something only when the configured log level is "info" or higher, you can write:

if configuedLogLevel >= log.Info {
  // Printed only when the configured log level is "info" or "debug"
  fmt.Println("something")
}
const (
	// Error is the error log level.
	Error Level = iota - 1
	// Info is the info log level.
	Info
	// Debug is the debug log level.
	Debug
)

func (Level) String

func (l Level) String() string

type Leveled

type Leveled struct {
	Debug, Info, Error Printer
	// contains filtered or unexported fields
}

func New

func New() *Leveled

func (*Leveled) Enabled

func (c *Leveled) Enabled(name string, level Level) bool

Enabled returns true if the given log entry is enabled.

The log entry is enabled if the TESTKIT_LOG environment variable contains the entry. Each entry is separated by a comma, and in the form of "name=level". The name is the name of the component that is logging, and the level is the log level. The level can be one of the following: "debug", "info", "warn", "error".

For example, "kind=debug" enables debug logging for the kind provider. The component that is logging should check if the log entry is enabled before logging.

That said, every component's logging code should look like this:

if l.Enabled("kind=debug") {
    l.Logf("debug message")
}

if l.Enabled("terraform=info") {
    l.Logf("info message")
}

Any Logf call that is not wrapped in an Enabled call is considered a bug.

The debug log is only printed if the TESTKIT_LOG environment variable contains any of the following entries: - "kind=debug" - "debug"

The info log is only printed if the TESTKIT_LOG environment variable contains any of the following entries: - "terraform=info" - "info" - "debug"

As said previously, TESTKIT_LOG is a comma-separated list of log entries. TESTKIT_LOG=kind=debug,terraform=info is valid, and enables debug logging for the kind provider and info logging for the terraform provider.

func (*Leveled) For

func (l *Leveled) For(name string) *namedLeveled

func (*Leveled) Logf

func (l *Leveled) Logf(name string, level Level, format string, a ...interface{})

func (*Leveled) Printf

func (d *Leveled) Printf(format string, a ...interface{})

type Logger

type Logger interface {
	Debugf(format string, a ...interface{})
	Infof(format string, a ...interface{})
	Errorf(format string, a ...interface{})
}

type Printer

type Printer interface {
	Printf(format string, a ...interface{})
}

Printer is the interface for loggers to print logs. It can be anything that implements Printf(string, ...interface{}).

type PrinterFunc

type PrinterFunc func(format string, a ...interface{})

func (PrinterFunc) Printf

func (f PrinterFunc) Printf(format string, a ...interface{})

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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