Documentation
¶
Index ¶
- Constants
- func AddFieldsFromCtx(logger logr.Logger, ctx context.Context, extensions context.Context) logr.Logger
- func NewComponentAwareSink(inner logr.LogSink, registry *ComponentLevelRegistry, ...) logr.LogSink
- func NewLogger(level LogLevel) logr.Logger
- func NewLoggerTo(destWriter io.Writer, level LogLevel) logr.Logger
- func NewLoggerToWithRegistry(destWriter io.Writer, level LogLevel, registry *ComponentLevelRegistry) logr.Logger
- func NewLoggerWithGlobalLevel() logr.Logger
- func NewLoggerWithRotation(level LogLevel, outputPath string, maxSize int, maxBackups int, maxAge int) logr.Logger
- func ResetMetrics()
- func SetGlobalLogLevel(level LogLevel)
- func SetupMetrics(reg prometheus.Registerer) (*prometheus.CounterVec, error)
- func SplitHierarchy(name string) []string
- func ValidateComponentName(name string) error
- type ComponentLevelRegistry
- func (r *ComponentLevelRegistry) GetEffectiveLevelForNames(names []string) (LogLevel, bool)
- func (r *ComponentLevelRegistry) ListOverrides() map[string]LogLevel
- func (r *ComponentLevelRegistry) ResetAll() map[string]LogLevel
- func (r *ComponentLevelRegistry) ResetLevel(component string)
- func (r *ComponentLevelRegistry) SetLevel(component string, level LogLevel) error
- type LogLevel
Constants ¶
const ( TenantLoggerKey = "tenantID" StreamIDLoggerKey = "streamID" )
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 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
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 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
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
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.