logging

package
v1.10.5 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package logging provides structured logging utilities for KubeVela webhooks with focus on request traceability and observability.

Index

Constants

View Source
const (
	// Core traceability fields
	FieldRequestID = "requestID"  // Unique identifier for request correlation
	FieldOperation = "operation"  // Webhook operation (CREATE/UPDATE/DELETE)
	FieldHandler   = "handler"    // Handler processing the request
	FieldStep      = "step"       // Current processing step
	FieldDuration  = "durationMs" // Operation duration in milliseconds

	// Resource identification
	FieldName       = "name"       // Resource name
	FieldNamespace  = "namespace"  // Resource namespace
	FieldKind       = "kind"       // Resource kind
	FieldGeneration = "generation" // Resource generation

	// User context
	FieldUserName = "user" // User making the request

	// Error tracking
	FieldError   = "error"   // Error indicator
	FieldSuccess = "success" // Success indicator
)

Structured logging field keys - consistent across all handlers for observability

Variables

This section is empty.

Functions

func RequestIDFrom

func RequestIDFrom(ctx context.Context) (string, bool)

RequestIDFrom retrieves request ID from context

func WithRequestID

func WithRequestID(ctx context.Context, requestID string) context.Context

WithRequestID stores request ID in context

Types

type Logger

type Logger struct {
	logr.Logger
}

Logger wraps logr.Logger with structured logging methods

func New

func New() Logger

New creates a new Logger

func NewHandlerLogger

func NewHandlerLogger(ctx context.Context, req admission.Request, handlerName string) Logger

NewHandlerLogger creates a logger for webhook handlers with full request context

func WithContext

func WithContext(ctx context.Context) Logger

WithContext returns a Logger from context or creates a new one

func (Logger) Debug

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

Debug logs debug message (verbosity 1)

func (Logger) Error

func (l Logger) Error(err error, msg string, keysAndValues ...interface{})

Error logs error message

func (Logger) Info

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

Info logs info message

func (Logger) IntoContext

func (l Logger) IntoContext(ctx context.Context) context.Context

IntoContext stores the Logger in context

func (Logger) Trace

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

Trace logs trace message (verbosity 2)

func (Logger) V

func (l Logger) V(level int) Logger

V returns a logger with verbosity level (0=info, 1=debug, 2=trace)

func (Logger) WithError

func (l Logger) WithError(err error) Logger

WithError adds error context to the logger

func (Logger) WithStep

func (l Logger) WithStep(step string) Logger

WithStep adds a step field to the logger

func (Logger) WithSuccess

func (l Logger) WithSuccess(success bool, startTime ...time.Time) Logger

WithSuccess adds success and duration fields to the logger

func (Logger) WithValues

func (l Logger) WithValues(keysAndValues ...interface{}) Logger

WithValues adds key-value pairs to the logger

Jump to

Keyboard shortcuts

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