...

Package log

import "github.com/chaos-mesh/chaos-mesh/pkg/log"
Overview
Index

Overview ▾

Package log contains series of utilities for setting up and accessing logger. We use logr.Logger as the facade of each logger.

See https://github.com/chaos-mesh/rfcs/blob/main/text/2021-12-09-logging.md for more details.

func EnrichLoggerWithContext

func EnrichLoggerWithContext(ctx context.Context, logger logr.Logger) logr.Logger

func L

func L() logr.Logger

L is the way to access the global logger. You could use it if there are no logger in your code context. Please notice that the default value of "global logger" is a "discard logger" which means that all logs will be ignored. Make sure that initialize the global logger by ReplaceGlobals before using it, for example, calling ReplaceGlobals at the beginning of your main function.

Do NOT save the global logger to a variable for long-term using, because it is possible that the global logger is replaced by another. Keep calling L at each time.

Deprecated: Do not use global logger anymore. For more detail, see https://github.com/chaos-mesh/rfcs/blob/main/text/2021-12-09-logging.md#global-logger

func NewDefaultZapLogger

func NewDefaultZapLogger() (logr.Logger, error)

NewDefaultZapLogger is the recommended way to create a new logger, you could call this function to initialize the root logger of your application, and provide it to your components, by fx or manually.

func NewZapLoggerWithWriter

func NewZapLoggerWithWriter(out io.Writer) logr.Logger

NewZapLoggerWithWriter creates a new logger with io.writer The provided encoder presets NewDevelopmentEncoderConfig used by NewDevelopmentConfig do not enable function name logging. To enable function name, a non-empty value for config.EncoderConfig.FunctionKey.

func ReplaceGlobals

func ReplaceGlobals(logger logr.Logger)

ReplaceGlobals would replace the global logger with the given logger. It should be used when your application starting.

Deprecated: Do not use global logger anymore. For more detail, see https://github.com/chaos-mesh/rfcs/blob/main/text/2021-12-09-logging.md#global-logger

type Metadatkey

type Metadatkey string
const (
    MetaNamespacedName Metadatkey = "namespaced-name"
)