log

package
v2.14.4 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TenantLoggerKey   = "tenantID"
	StreamIDLoggerKey = "streamID"
)
View Source
const MaxOverrides = 200

MaxOverrides is the maximum number of per-component level overrides allowed in a single registry. This prevents unbounded memory growth from misconfigured or malicious API clients.

Variables

This section is empty.

Functions

func AddFieldsFromCtx

func AddFieldsFromCtx(
	logger logr.Logger,
	ctx context.Context,
	extensions context.Context,
) logr.Logger

AddFieldsFromCtx will check if provided context contain tracing span and if the span is currently recording. If so, it will call spanLogValuesProcessor function if it's also present in the context. If not it will add trace_id and span_id to logged values. It will also add the tenant id to the logged values.

func NewComponentAwareSink added in v2.14.0

func NewComponentAwareSink(inner logr.LogSink, registry *ComponentLevelRegistry, baseLevel *zap.AtomicLevel) logr.LogSink

NewComponentAwareSink wraps an existing LogSink with per-component level awareness. The inner sink should be created at max verbosity. baseLevel is used as fallback when no per-component override is set.

func NewLogger

func NewLogger(level LogLevel) logr.Logger

func NewLoggerTo

func NewLoggerTo(destWriter io.Writer, level LogLevel) logr.Logger

func NewLoggerToWithRegistry added in v2.14.0

func NewLoggerToWithRegistry(destWriter io.Writer, level LogLevel, registry *ComponentLevelRegistry) logr.Logger

NewLoggerToWithRegistry creates a logger writing to destWriter using the given registry for per-component level overrides. The inner zap logger is created at max verbosity — all level filtering is done by the sink.

func NewLoggerWithGlobalLevel added in v2.13.0

func NewLoggerWithGlobalLevel() logr.Logger

NewLoggerWithGlobalLevel creates a logger that uses the global atomic level. The log level can be changed dynamically using SetGlobalLogLevel without replacing the logger instance. This is useful for early initialization (e.g., in init() functions) where the final log level is not yet known.

func NewLoggerWithRotation

func NewLoggerWithRotation(level LogLevel, outputPath string, maxSize int, maxBackups int, maxAge int) logr.Logger

func ResetMetrics added in v2.14.0

func ResetMetrics()

ResetMetrics clears the global log-lines counter. Intended for test teardown to prevent counter state from leaking across packages.

func SetGlobalLogLevel added in v2.13.0

func SetGlobalLogLevel(level LogLevel)

SetGlobalLogLevel updates the global atomic log level used by loggers created with NewLoggerWithGlobalLevel. This allows changing the log level of all such loggers without replacing the logger instances.

func SetupMetrics added in v2.14.0

func SetupMetrics(reg prometheus.Registerer) (*prometheus.CounterVec, error)

SetupMetrics registers the kuma_cp_log_lines_total counter with the given registerer.

func SplitHierarchy added in v2.14.0

func SplitHierarchy(name string) []string

SplitHierarchy returns the name and all its ancestors, most-specific first. e.g. "xds.server" → ["xds.server", "xds"]

func ValidateComponentName added in v2.14.0

func ValidateComponentName(name string) error

ValidateComponentName checks that the component name is well-formed: non-empty, at most 256 characters, alphanumeric with dots/dashes/underscores.

Types

type ComponentLevelRegistry added in v2.14.0

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

ComponentLevelRegistry holds per-component log level overrides. Components are identified by dot-separated names matching the hierarchy built by logr.Logger.WithName() calls (e.g. "xds.server").

Reads are lock-free via an atomic pointer to an immutable snapshot. Writes acquire a mutex and swap in a new copy (copy-on-write).

func GlobalComponentLevelRegistry added in v2.14.0

func GlobalComponentLevelRegistry() *ComponentLevelRegistry

GlobalComponentLevelRegistry returns the singleton registry used to manage per-component log level overrides.

func NewComponentLevelRegistry added in v2.14.0

func NewComponentLevelRegistry() *ComponentLevelRegistry

NewComponentLevelRegistry creates a new empty registry, mainly for testing.

func (*ComponentLevelRegistry) GetEffectiveLevelForNames added in v2.14.0

func (r *ComponentLevelRegistry) GetEffectiveLevelForNames(names []string) (LogLevel, bool)

GetEffectiveLevelForNames returns the effective log level given a pre-computed name hierarchy (most-specific first). This avoids string splitting on the hot path when called from componentAwareSink.Enabled.

func (*ComponentLevelRegistry) ListOverrides added in v2.14.0

func (r *ComponentLevelRegistry) ListOverrides() map[string]LogLevel

ListOverrides returns a snapshot of all current component level overrides.

func (*ComponentLevelRegistry) ResetAll added in v2.14.0

func (r *ComponentLevelRegistry) ResetAll() map[string]LogLevel

ResetAll removes all component log level overrides and returns the overrides that were active before the reset.

func (*ComponentLevelRegistry) ResetLevel added in v2.14.0

func (r *ComponentLevelRegistry) ResetLevel(component string)

ResetLevel removes the log level override for the given component.

func (*ComponentLevelRegistry) SetLevel added in v2.14.0

func (r *ComponentLevelRegistry) SetLevel(component string, level LogLevel) error

SetLevel sets a log level override for the given component. Returns an error if the maximum number of overrides would be exceeded.

type LogLevel

type LogLevel int
const (
	OffLevel LogLevel = iota
	InfoLevel
	DebugLevel
)

func ParseLogLevel

func ParseLogLevel(text string) (LogLevel, error)

func (LogLevel) String

func (l LogLevel) String() string

Jump to

Keyboard shortcuts

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