log

package
v0.1.6 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// we can only have info, debug and error log levels when using
	// logr/zapr: https://github.com/go-logr/logr/issues/258
	INFO                 = 0
	DEBUG                = 1
	DebugLevel LogLevel  = "debug"
	InfoLevel  LogLevel  = "info"
	TextFormat LogFormat = "text"
	JsonFormat LogFormat = "json"
)
View Source
const (
	EphemeralLogLevel  = "EPHEMERAL_LOG_LEVEL"
	EphemeralLogFormat = "EPHEMERAL_LOG_FORMAT"
)

Variables

This section is empty.

Functions

func NewLogger

func NewLogger(opts ...Opts) (logr.Logger, error)

NewLogger will use the given opts to build a new logr.Logger instance. It will use zap and the underlying Logger implementation. This function should be called only during the service initialization.

func NewPluginLogger

func NewPluginLogger(opts ...Opts) (hclog.Logger, error)

NewPluginLogger will initialize a logger to be used in ephemeral-access plugins.

func NewZapLogger

func NewZapLogger(opts ...Opts) (*zap.Logger, error)

NewZapLogger will initialize and return a new zap.Logger

Types

type Fake

type Fake struct{}

Fake logger implementation to be used in tests

func NewFake

func NewFake() *Fake

NewFake will instantiate a new fake logger to be used in tests

func (*Fake) Debug

func (l *Fake) Debug(msg string, keysAndValues ...any)

Debug noop

func (*Fake) Error

func (l *Fake) Error(err error, msg string, keysAndValues ...any)

Error noop

func (*Fake) Info

func (l *Fake) Info(msg string, keysAndValues ...any)

Info noop

type LogConfig

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

LogConfig is a LogConfigurer implementation

type LogFormat

type LogFormat string

LogFormat can be TextFormat or JsonFormat

func (LogFormat) String

func (l LogFormat) String() string

String will return the string representation for this LogFormat

type LogLevel

type LogLevel string

LogLevel can be DebugLevel or InfoLevel

func (LogLevel) String

func (l LogLevel) String() string

String will return the string representation for this LogLevel

type LogWrapper

type LogWrapper struct {
	Logger *logr.Logger
}

LogWrapper provides more expressive methods than the ones provided by the logr.Logger interface abstracting away the usage of numeric log levels.

func FromContext

func FromContext(ctx context.Context, keysAndValues ...interface{}) *LogWrapper

FromContext will return a new log wrapper with the extracted logger from the given context.

func New

func New(opts ...Opts) (*LogWrapper, error)

New will initialize a new log wrapper with the provided logger.

func (*LogWrapper) Debug

func (l *LogWrapper) Debug(msg string, keysAndValues ...any)

Debug logs a non-error message with debug level. If provided, the given key/value pairs are added in the log entry context.

func (*LogWrapper) Error

func (l *LogWrapper) Error(err error, msg string, keysAndValues ...any)

Error logs an error message. If provided, the given key/value pairs are added in the log entry context.

func (*LogWrapper) Info

func (l *LogWrapper) Info(msg string, keysAndValues ...any)

Info logs a non-error message with info level. If provided, the given key/value pairs are added in the log entry context.

type Logger

type Logger interface {
	Info(msg string, keysAndValues ...any)
	Debug(msg string, keysAndValues ...any)
	Error(err error, msg string, keysAndValues ...any)
}

Logger defines the main logger contract used by this project.

type Opts

type Opts func(*LogConfig)

func WithFormat

func WithFormat(format LogFormat) Opts

func WithLevel

func WithLevel(level LogLevel) Opts

Jump to

Keyboard shortcuts

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