vzlog

package
v0.0.0-...-a7b7215 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: UPL-1.0 Imports: 11 Imported by: 5

Documentation

Index

Constants

View Source
const (
	FieldResourceNamespace = "resource_namespace"
	FieldResourceName      = "resource_name"
	FieldController        = "controller"
	FieldWebhook           = "webhook"
	FieldAgent             = "agent"
)

Variables

View Source
var LogContextMap = make(map[string]*LogContext)

LogContextMap contains a map of LogContext objects

Functions

func BuildZapInfoLogger

func BuildZapInfoLogger(callerSkip int) (*zap.SugaredLogger, error)

BuildZapInfoLogger initializes a zap logger at info level

func BuildZapLoggerWithLevel

func BuildZapLoggerWithLevel(callerSkip int, level zapcore.Level) (*zap.SugaredLogger, error)

BuildZapLoggerWithLevel initializes a zap logger for a given log level

func ConflictWithLog

func ConflictWithLog(message string, err error, log *zap.SugaredLogger) error

ConflictWithLog returns a conflict error and logs a message Returned is an error

func DeleteLogContext

func DeleteLogContext(key string)

DeleteLogContext deletes the LogContext for the given key

func GetDebugEnabledLogger

func GetDebugEnabledLogger() *zap.SugaredLogger

GetDebugEnabledLogger Mostly useful for getting a debug enabled logger for unit tests

func IgnoreConflictWithLog

func IgnoreConflictWithLog(message string, err error, log *zap.SugaredLogger) (result.Result, error)

IgnoreConflictWithLog ignores conflict error and logs a message Returned is a result and an error

func InitLogs

func InitLogs(opts kzap.Options)

InitLogs initializes logs with Time and Global Level of Logs set at Info

func ResultErrorsWithLog

func ResultErrorsWithLog(message string, errors []error, log *zap.SugaredLogger)

ResultErrorsWithLog logs an error message for any error that is not a conflict error. Conflict errors are logged with debug level messages.

Types

type LogContext

type LogContext struct {

	// Generation is the generation of the resource being logged
	Generation int64

	// RootZapLogger is the zap SugaredLogger for the resource. Component loggers are derived from this.
	RootZapLogger *zap.SugaredLogger
	// contains filtered or unexported fields
}

LogContext is the log context for a given resource. This logger can be used to manage logging for the resource and sub-resources, such as components

func EnsureContext

func EnsureContext(key string) *LogContext

EnsureContext ensures that a LogContext exists The key must be unique for the process, for example a namespace/name combo.

func (*LogContext) EnsureLogger

func (c *LogContext) EnsureLogger(key string, sLogger SugaredLogger, zap *zap.SugaredLogger) VerrazzanoLogger

EnsureLogger ensures that a new VerrazzanoLogger exists for the given key

type ProgressLogger

type ProgressLogger interface {
	// Once logs a message once at Info log level
	Once(args ...interface{})

	// Oncef formats a message and logs it once at Info log level
	Oncef(template string, args ...interface{})

	// Progress logs a message periodically at Info log level
	Progress(args ...interface{})

	// Progress formats a message and logs it periodically at Info log level
	Progressf(template string, args ...interface{})

	// ErrorNewErr logs and error, then returns the error
	ErrorNewErr(args ...interface{}) error

	// ErrorfNewErr formats an error, logs it, then returns the formatted error
	ErrorfNewErr(template string, args ...interface{}) error

	// ErrorfThrottledNewErr Records a formatted error message throttled at the ProgressLogger frequency then returns the formatted error
	ErrorfThrottledNewErr(template string, args ...interface{}) error

	// ErrorfThrottled Records a formatted error message throttled at the ProgressLogger frequency
	ErrorfThrottled(template string, args ...interface{})

	// SetFrequency sets the logging frequency of a progress message
	SetFrequency(secs int) VerrazzanoLogger
}

ProgressLogger is a logger interface that provides Verrazzano base and progress logging

type ResourceConfig

type ResourceConfig struct {
	// Name is the name of the resource
	Name string

	// Namespace is the namespace of the resource
	Namespace string

	// ID is the resource uid
	ID string

	// Generation is the resource generation
	Generation int64

	// Controller name is the name of the controller
	ControllerName string
}

ResourceConfig is the configuration of a logger for a resource that is being reconciled

type SugaredLogger

type SugaredLogger interface {
	// Debug logs a message at Debug log level
	Debug(args ...interface{})

	// Debugf formats a message and logs it once at Debug log level
	Debugf(template string, args ...interface{})

	// Debugw formats a message and logs it once at Debug log level
	Debugw(msg string, args ...interface{})

	// Info logs a message at Info log level
	Info(args ...interface{})

	// Infof formats a message and logs it once at Info log level
	Infof(template string, args ...interface{})

	// Infow formats a message and logs it once at Info log level
	Infow(msg string, keysAndValues ...interface{})

	// Error logs a message at Error log level
	Error(args ...interface{})

	// Errorf formats a message and logs it once at Error log level
	Errorf(template string, args ...interface{})

	// Errorw formats a message and logs it once at Error log level
	Errorw(msg string, keysAndValues ...interface{})
}

SugaredLogger is a logger interface that provides base logging

type VerrazzanoLogger

type VerrazzanoLogger interface {
	SugaredLogger
	ProgressLogger

	// SetZapLogger sets the zap logger
	SetZapLogger(zap *zap.SugaredLogger)

	// GetZapLogger gets the zap logger
	GetZapLogger() *zap.SugaredLogger

	// GetRootZapLogger gets the root zap logger
	GetRootZapLogger() *zap.SugaredLogger

	// GetContext gets the log context
	GetContext() *LogContext
}

VerrazzanoLogger is a logger interface that provides sugared and progress logging

func DefaultLogger

func DefaultLogger() VerrazzanoLogger

DefaultLogger ensures the default logger exists. This is typically used for testing

func EnsureResourceLogger

func EnsureResourceLogger(config *ResourceConfig) (VerrazzanoLogger, error)

EnsureResourceLogger ensures that a logger exists for a specific generation of a Kubernetes resource. When a resource is getting reconciled, the status may frequently get updated during the reconciliation. This is the case for the Verrazzano resource. As a result, the controller-runtime queue gets filled with updated instances of a resource that have the same generation. The side-effect is that after a resource is completely reconciled, the controller Reconcile method may still be called many times. In this case, the existing context must be used so that 'once' and 'progress' messages don't start from a new context, causing them to be displayed when they shouldn't. This mehod ensures that the same logger is used for a given resource and generation.

func ForZapLogger

func ForZapLogger(config *ResourceConfig, zaplog *zap.SugaredLogger) VerrazzanoLogger

Jump to

Keyboard shortcuts

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