logging

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2023 License: AGPL-3.0 Imports: 9 Imported by: 125

Documentation

Overview

Package logging package contains functionality for viam-server logging.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewLoggerConfig added in v0.12.0

func NewLoggerConfig() zap.Config

NewLoggerConfig returns a new default logger config.

func ReplaceGlobal added in v0.12.0

func ReplaceGlobal(logger Logger)

ReplaceGlobal replaces the global loggers.

Types

type Level

type Level int

Level is an enum of log levels. Its value can be `DEBUG`, `INFO`, `WARN` or `ERROR`.

const (

	// DEBUG log level.
	DEBUG Level = iota - 1
	// INFO log level.
	INFO
	// WARN log level.
	WARN
	// ERROR log level.
	ERROR
)

func LevelFromString

func LevelFromString(inp string) (Level, error)

LevelFromString parses an input string to a log level. The string must be one of `debug`, `info`, `warn` or `error`. The parsing is case-insensitive. An error is returned if the input does not match one of labeled cases.

func (Level) MarshalJSON

func (level Level) MarshalJSON() ([]byte, error)

MarshalJSON converts a log level to a json string.

func (Level) String

func (level Level) String() string

func (*Level) UnmarshalJSON

func (level *Level) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON converts a json string to a log level.

type Logger added in v0.12.0

type Logger interface {
	ZapCompatibleLogger

	AsZap() *zap.SugaredLogger
}

Logger interface for logging to.

func FromZapCompatible added in v0.12.0

func FromZapCompatible(logger ZapCompatibleLogger) Logger

FromZapCompatible upconverts a ZapCompatibleLogger to a logging.Logger. If the argument already satisfies logging.Logger, no changes will be made. A nil input returns a nil logger. An input of unknown type will create a new logger that's not associated with the input.

func Global added in v0.12.0

func Global() Logger

Global returns the global logger.

func NewDebugLogger added in v0.12.0

func NewDebugLogger(name string) Logger

NewDebugLogger returns a new logger using the default debug configuration.

func NewLogger added in v0.12.0

func NewLogger(name string) Logger

NewLogger returns a new logger using the default production configuration.

func NewObservedTestLogger added in v0.12.0

func NewObservedTestLogger(tb testing.TB) (Logger, *observer.ObservedLogs)

NewObservedTestLogger is like NewTestLogger but also saves logs to an in memory observer.

func NewTestLogger added in v0.12.0

func NewTestLogger(tb testing.TB) Logger

NewTestLogger directs logs to the go test logger.

type ZapCompatibleLogger added in v0.12.0

type ZapCompatibleLogger interface {
	Desugar() *zap.Logger
	Level() zapcore.Level
	Named(name string) *zap.SugaredLogger
	Sync() error
	With(args ...interface{}) *zap.SugaredLogger
	WithOptions(opts ...zap.Option) *zap.SugaredLogger

	Debug(args ...interface{})
	Debugf(template string, args ...interface{})
	Debugw(msg string, keysAndValues ...interface{})

	Info(args ...interface{})
	Infof(template string, args ...interface{})
	Infow(msg string, keysAndValues ...interface{})

	Warn(args ...interface{})
	Warnf(template string, args ...interface{})
	Warnw(msg string, keysAndValues ...interface{})

	Error(args ...interface{})
	Errorf(template string, args ...interface{})
	Errorw(msg string, keysAndValues ...interface{})

	Fatal(args ...interface{})
	Fatalf(template string, args ...interface{})
	Fatalw(msg string, keysAndValues ...interface{})
}

ZapCompatibleLogger is a backwards compatibility layer for existing usages of the RDK as a library for Go application code or modules. Public (to the library) methods that take a logger as input should accept this type and upconvert to a Logger via a call to `FromZapCompatible`.

Jump to

Keyboard shortcuts

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