log

package
v0.0.0-...-350a2fb Latest Latest
Warning

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

Go to latest
Published: May 30, 2024 License: Apache-2.0 Imports: 11 Imported by: 38

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendZapFieldToCtx

func AppendZapFieldToCtx(ctx context.Context, newFields ...zap.Field) context.Context

AppendZapFieldToCtx attaches new fields to the context, which can be then used with log.WithCtx().

func InitLogger

func InitLogger(cfg *Config) error

InitLogger initializes DM's and also the TiDB library's loggers.

func Props

func Props() *pclog.ZapProperties

Props returns the current logger's props.

func SetLevel

func SetLevel(level zapcore.Level) zapcore.Level

SetLevel modifies the log level of the global logger. Returns the previous level.

func ShortError

func ShortError(err error) zap.Field

ShortError contructs a field which only records the error message without the verbose text (i.e. excludes the stack trace).

In DM, all errors are almost always propagated back to `main()` where the error stack is written. Including the stack in the middle thus usually just repeats known information. You should almost always use `ShortError` instead of `zap.Error`, unless the error is no longer propagated upwards.

func WrapStringerField

func WrapStringerField(message string, object fmt.Stringer) zap.Field

WrapStringerField returns a wrap stringer field.

Types

type Config

type Config struct {
	// Log level.
	Level string `toml:"level" json:"level"`
	// the format of the log, "text" or "json"
	Format string `toml:"format" json:"format"`
	// Log filename, leave empty to disable file log.
	File string `toml:"file" json:"file"`
	// Max size for a single file, in MB.
	FileMaxSize int `toml:"max-size" json:"max-size"`
	// Max log keep days, default is never deleting.
	FileMaxDays int `toml:"max-days" json:"max-days"`
	// Maximum number of old log files to retain.
	FileMaxBackups int `toml:"max-backups" json:"max-backups"`
}

Config serializes log related config in toml/json.

func (*Config) Adjust

func (cfg *Config) Adjust()

Adjust adjusts config.

type Logger

type Logger struct {
	*zap.Logger
}

Logger is a simple wrapper around *zap.Logger which provides some extra methods to simplify DM's log usage.

func L

func L() Logger

L returns the current logger for DM.

func With

func With(fields ...zap.Field) Logger

With creates a child logger from the global logger and adds structured context to it.

func WithCtx

func WithCtx(ctx context.Context) Logger

WithCtx adds fields from ctx to the logger.

func (Logger) ErrorFilterContextCanceled

func (l Logger) ErrorFilterContextCanceled(msg string, fields ...zap.Field)

ErrorFilterContextCanceled wraps Logger.Error() and will filter error log when error is context.Canceled.

func (Logger) WithFields

func (l Logger) WithFields(fields ...zap.Field) Logger

WithFields return new Logger with specified fields.

Jump to

Keyboard shortcuts

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