ctxlog

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2021 License: Apache-2.0 Imports: 10 Imported by: 21

Documentation

Overview

Package ctxlog extends ctxlog with events

Index

Constants

View Source
const (
	// ReasonPredicates is used for controller predicate related logging
	ReasonPredicates = "Predicates"
	// ReasonMapping is used for controller EnqueueRequestsFromMapFunc related logging
	ReasonMapping = "Mapping"
)

Variables

This section is empty.

Functions

func Debug

func Debug(ctx context.Context, v ...interface{})

Debug uses the stored zap logger

func Debugf

func Debugf(ctx context.Context, format string, v ...interface{})

Debugf uses the stored zap logger

func Error

func Error(ctx context.Context, v ...interface{})

Error uses the stored zap logger

func Errorf

func Errorf(ctx context.Context, format string, v ...interface{})

Errorf uses the stored zap logger

func ExtractLogger

func ExtractLogger(ctx context.Context) *zap.SugaredLogger

ExtractLogger returns the logger from the context

func ExtractLoggerWithOptions

func ExtractLoggerWithOptions(ctx context.Context, options ...zap.Option) *zap.SugaredLogger

ExtractLoggerWithOptions returns a logger with different options than the parent

func ExtractRecorder

func ExtractRecorder(ctx context.Context) record.EventRecorder

ExtractRecorder returns the event recorder from the context

func Info

func Info(ctx context.Context, v ...interface{})

Info uses the stored zap logger

func Infof

func Infof(ctx context.Context, format string, v ...interface{})

Infof uses the stored zap logger

func NewContextWithRecorder

func NewContextWithRecorder(ctx context.Context, name string, recorder record.EventRecorder) context.Context

NewContextWithRecorder returns a new child context with the named recorder and log inside

func NewParentContext

func NewParentContext(log *zap.SugaredLogger) context.Context

NewParentContext returns a new context with a logger

func WarningEvent

func WarningEvent(ctx context.Context, object runtime.Object, reason, msg string)

WarningEvent will create a warning event, without logging

Types

type Event

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

Event holds information about a k8s events we create via controller-runtime's event recorder

func WithEvent

func WithEvent(object runtime.Object, reason string) Event

WithEvent returns a struct to provide event enhanced logging methods 'object' is the object this event is about. Event will make a reference-- or you may also pass a reference to the object directly. 'reason' is the reason this event is generated. 'reason' should be short and unique; it should be in UpperCamelCase format (starting with a capital letter). "reason" will be used to automate handling of events, so imagine people writing switch statements to handle them. You want to make that easy.

func (Event) Debugf

func (ev Event) Debugf(ctx context.Context, format string, v ...interface{})

Debugf logs and adds an info event

func (Event) Error

func (ev Event) Error(ctx context.Context, parts ...interface{}) error

Error uses the stored zap logger and recorder

func (Event) Errorf

func (ev Event) Errorf(ctx context.Context, format string, v ...interface{}) error

Errorf uses the stored zap logger and the recorder to log an error, it returns an error like fmt.Errorf

func (Event) Infof

func (ev Event) Infof(ctx context.Context, format string, v ...interface{})

Infof logs and adds an info event

type MappingEvent

type MappingEvent struct {
	Event
}

MappingEvent is used to debug EnqueueRequestsFromMapFunc in controllers

func NewMappingEvent

func NewMappingEvent(object runtime.Object) MappingEvent

NewMappingEvent returns a log event with the 'mapping' reason

func (MappingEvent) Debug

func (ev MappingEvent) Debug(ctx context.Context, reconciliation reconcile.Request, crd string, objName string, objType string)

Debug is used for logging in EnqueueRequestsFromMapFunc

type PredicateEvent

type PredicateEvent struct {
	Event
}

PredicateEvent is used to debug controller predicates

func NewPredicateEvent

func NewPredicateEvent(object runtime.Object) PredicateEvent

NewPredicateEvent returns a log event with the 'predicate' reason

func (PredicateEvent) Debug

func (ev PredicateEvent) Debug(ctx context.Context, meta metav1.Object, resource string, msg string)

Debug is used for predicate logging in the controllers

type ReconcileEventsFromSource

type ReconcileEventsFromSource struct {
	ReconciliationObjectName string `json:"reconciliationObjectName"`
	ReconciliationObjectKind string `json:"reconciliationObjectKind"`
	PredicateObjectName      string `json:"predicateObjectName"`
	PredicateObjectKind      string `json:"predicateObjectKind"`
	Namespace                string `json:"namespace"`
	Message                  string `json:"message"`
	Type                     string `json:"type"`
}

ReconcileEventsFromSource for defining useful logs when defining a mapping between a watched object and a reconcile one

Jump to

Keyboard shortcuts

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