Documentation
¶
Overview ¶
Package logging provides structured logging utilities for KubeVela webhooks with focus on request traceability and observability.
Index ¶
- Constants
- func NewColorWriter(dst io.Writer) io.Writer
- func RequestIDFrom(ctx context.Context) (string, bool)
- func WithRequestID(ctx context.Context, requestID string) context.Context
- type Logger
- func (l Logger) Debug(msg string, keysAndValues ...interface{})
- func (l Logger) Error(err error, msg string, keysAndValues ...interface{})
- func (l Logger) Info(msg string, keysAndValues ...interface{})
- func (l Logger) IntoContext(ctx context.Context) context.Context
- func (l Logger) Trace(msg string, keysAndValues ...interface{})
- func (l Logger) V(level int) Logger
- func (l Logger) WithError(err error) Logger
- func (l Logger) WithStep(step string) Logger
- func (l Logger) WithSuccess(success bool, startTime ...time.Time) Logger
- func (l Logger) WithValues(keysAndValues ...interface{}) Logger
Constants ¶
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 NewColorWriter ¶
NewColorWriter creates a new writer that adds ANSI color codes to klog output. It wraps the provided writer and colorizes log messages based on severity level, enhances location information with function names, and formats structured fields. This is primarily intended for development mode (--dev-logs=true) to improve log readability in terminal output.
func RequestIDFrom ¶
RequestIDFrom retrieves request ID from context
Types ¶
type Logger ¶
Logger wraps logr.Logger with structured logging methods
func NewHandlerLogger ¶
NewHandlerLogger creates a logger for webhook handlers with full request context
func WithContext ¶
WithContext returns a Logger from context or creates a new one
func (Logger) IntoContext ¶
IntoContext stores the Logger in context
func (Logger) WithSuccess ¶
WithSuccess adds success and duration fields to the logger
func (Logger) WithValues ¶
WithValues adds key-value pairs to the logger