logging

package
v0.0.0-...-b77a78c Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2023 License: Apache-2.0 Imports: 13 Imported by: 5,505

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigMapName

func ConfigMapName() string

ConfigMapName gets the name of the logging ConfigMap

func ConfigToJSON

func ConfigToJSON(cfg *Config) (string, error)

ConfigToJSON converts a Config to a JSON string.

func FromContext

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

FromContext returns the logger stored in context. Returns nil if no logger is set in context, or if the stored value is not of correct type.

func NewLogger

func NewLogger(configJSON string, levelOverride string, opts ...zap.Option) (*zap.SugaredLogger, zap.AtomicLevel)

NewLogger creates a logger with the supplied configuration. In addition to the logger, it returns AtomicLevel that can be used to change the logging level at runtime. If configuration is empty, a fallback configuration is used. If configuration cannot be used to instantiate a logger, the same fallback configuration is used.

func NewLoggerFromConfig

func NewLoggerFromConfig(config *Config, name string, opts ...zap.Option) (*zap.SugaredLogger, zap.AtomicLevel)

NewLoggerFromConfig creates a logger using the provided Config

func StringSet

StringSet returns a marshaler for the set of strings. To use this in sugared logger do:

logger.Infow("Revision State", zap.Object("healthy", logging.StringSet(healthySet)),
	zap.Object("unhealthy", logging.StringSet(unhealthySet)))

To use with non-sugared logger do:

logger.Info("Revision State", zap.Object("healthy", logging.StringSet(healthySet)),
	zap.Object("unhealthy", logging.StringSet(unhealthySet)))

func UpdateLevelFromConfigMap

func UpdateLevelFromConfigMap(logger *zap.SugaredLogger, atomicLevel zap.AtomicLevel,
	levelKey string) func(configMap *corev1.ConfigMap)

UpdateLevelFromConfigMap returns a helper func that can be used to update the logging level when a config map is updated

func WithConfig

func WithConfig(ctx context.Context, cfg *Config) context.Context

WithConfig associates a logging configuration with the context.

func WithLogger

func WithLogger(ctx context.Context, logger *zap.SugaredLogger) context.Context

WithLogger returns a copy of parent context in which the value associated with logger key is the supplied logger.

Types

type Config

type Config struct {
	LoggingConfig string
	LoggingLevel  map[string]zapcore.Level
}

Config contains the configuration defined in the logging ConfigMap. +k8s:deepcopy-gen=true

func GetConfig

func GetConfig(ctx context.Context) *Config

GetConfig gets the logging config from the provided context.

func JSONToConfig

func JSONToConfig(jsonCfg string) (*Config, error)

JSONToConfig converts a JSON string of a Config. Always returns a non-nil Config.

func NewConfigFromConfigMap

func NewConfigFromConfigMap(configMap *corev1.ConfigMap) (*Config, error)

NewConfigFromConfigMap creates a Config from the supplied ConfigMap, expecting the given list of components.

func NewConfigFromMap

func NewConfigFromMap(data map[string]string) (*Config, error)

NewConfigFromMap creates a LoggingConfig from the supplied map, expecting the given list of components.

func (*Config) DeepCopy

func (in *Config) DeepCopy() *Config

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Config.

func (*Config) DeepCopyInto

func (in *Config) DeepCopyInto(out *Config)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

type WarningHandler

type WarningHandler struct {
	Logger *zap.SugaredLogger
}

WarningHandler is a warning handler to forward client-go's warning logs into a zap logger.

func (*WarningHandler) HandleWarningHeader

func (h *WarningHandler) HandleWarningHeader(code int, agent string, message string)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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