logger

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: MIT Imports: 8 Imported by: 10 modules, 112 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Critical deprecated

func Critical(l Logger, args ...interface{})

Deprecated: instead use SugaredLogger.Critical:

Sugared(l).Critical(args...)

func Criticalf deprecated

func Criticalf(l Logger, format string, values ...interface{})

Deprecated: instead use SugaredLogger.Criticalf:

Sugared(l).Criticalf(args...)

func Criticalw deprecated

func Criticalw(l Logger, msg string, keysAndValues ...interface{})

Deprecated: instead use SugaredLogger.Criticalw:

Sugared(l).Criticalw(args...)

func NewOCRWrapper

func NewOCRWrapper(l Logger, trace bool, saveError func(string)) ocrtypes.Logger

NewOCRWrapper returns a new ocrtypes.Logger backed by the given Logger. Note: trace logs are written at debug level, regardless of any build tags.

func Trace deprecated

func Trace(l Logger, args ...interface{})

Deprecated: instead use SugaredLogger.Trace:

Sugared(l).Trace(args...)

func Tracef deprecated

func Tracef(l Logger, format string, values ...interface{})

Deprecated: instead use SugaredLogger.Tracef:

Sugared(l).Tracef(args...)

func Tracew deprecated

func Tracew(l Logger, msg string, keysAndValues ...interface{})

Deprecated: instead use SugaredLogger.Tracew:

Sugared(l).Tracew(args...)

Types

type Config

type Config struct {
	Level zapcore.Level
}

func (*Config) New

func (c *Config) New() (Logger, error)

New returns a new Logger for Config.

type Logger

type Logger interface {
	Name() string

	Debug(args ...interface{})
	Info(args ...interface{})
	Warn(args ...interface{})
	Error(args ...interface{})
	Panic(args ...interface{})
	Fatal(args ...interface{})

	Debugf(format string, values ...interface{})
	Infof(format string, values ...interface{})
	Warnf(format string, values ...interface{})
	Errorf(format string, values ...interface{})
	Panicf(format string, values ...interface{})
	Fatalf(format string, values ...interface{})

	Debugw(msg string, keysAndValues ...interface{})
	Infow(msg string, keysAndValues ...interface{})
	Warnw(msg string, keysAndValues ...interface{})
	Errorw(msg string, keysAndValues ...interface{})
	Panicw(msg string, keysAndValues ...interface{})
	Fatalw(msg string, keysAndValues ...interface{})

	Sync() error
}

Logger is a minimal subset of goplugin/pluginv3.0/core/logger.Logger implemented by go.uber.org/zap.SugaredLogger

func Helper

func Helper(l Logger, skip int) Logger

Helper returns a logger with 'skip' levels of callers skipped, if 'l' has a method `Helper(int) L`, where L implements Logger, otherwise it returns l. See zap.AddCallerSkip

func Named

func Named(l Logger, n string) Logger

Named returns a logger with name 'n', if 'l' has a method `Named(string) L`, where L implements Logger, otherwise it returns l.

func New

func New() (Logger, error)

New returns a new Logger with the default configuration.

func NewWith

func NewWith(cfgFn func(*zap.Config)) (Logger, error)

NewWith returns a new Logger from a modified zap.Config.

func NewWithSync

func NewWithSync(w io.Writer) Logger

NewWithSync returns a new Logger with a given SyncWriter.

func Nop

func Nop() Logger

Nop returns a no-op Logger.

func Test

func Test(tb testing.TB) Logger

Test returns a new test Logger for tb.

func TestObserved

func TestObserved(tb testing.TB, lvl zapcore.Level) (Logger, *observer.ObservedLogs)

TestObserved returns a new test Logger for tb and ObservedLogs at the given Level.

func With

func With(l Logger, keyvals ...interface{}) Logger

With returns a Logger with keyvals, if 'l' has a method `With(...interface{}) L`, where L implements Logger, otherwise it returns l.

type SugaredLogger

type SugaredLogger interface {
	Logger

	// AssumptionViolation variants log at error level with the message prefix "AssumptionViolation: ".
	AssumptionViolation(args ...interface{})
	AssumptionViolationf(format string, vals ...interface{})
	AssumptionViolationw(msg string, keysAndVals ...interface{})

	// ErrorIf logs the error if present.
	ErrorIf(err error, msg string)
	// ErrorIfFn calls fn() and logs any returned error along with msg.
	// Unlike ErrorIf, this can be deffered inline, since the function call is delayed:
	//
	//	defer lggr.ErrorIfFn(resource.Close, "Failed to close resource")
	ErrorIfFn(fn func() error, msg string)

	// Critical emits critical level logs (a remapping of [zap.DPanicLevel]) or falls back to error level with a '[crit]' prefix.
	Critical(args ...interface{})
	Criticalf(format string, vals ...interface{})
	Criticalw(msg string, keysAndVals ...interface{})

	// Trace emits logs only when built with the 'trace' tag.
	//
	//	go test -tags trace ./foo -run TestBar
	Trace(args ...interface{})
	Tracef(format string, vals ...interface{})
	Tracew(msg string, keysAndVals ...interface{})

	Named(string) SugaredLogger
	With(keyvals ...any) SugaredLogger
	Helper(skip int) SugaredLogger
}

SugaredLogger extends the base Logger interface with syntactic sugar, similar to zap.SugaredLogger.

func Sugared

func Sugared(l Logger) SugaredLogger

Sugared returns a new SugaredLogger wrapping the given Logger. Prefer to store the SugaredLogger for reuse, instead of recreating it as needed.

func TestObservedSugared

func TestObservedSugared(tb testing.TB, lvl zapcore.Level) (SugaredLogger, *observer.ObservedLogs)

TestObservedSugared returns a new test SugaredLogger for tb and ObservedLogs at the given Level.

func TestSugared

func TestSugared(tb testing.TB) SugaredLogger

TestSugared returns a new test SugaredLogger.

Jump to

Keyboard shortcuts

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