log

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2021 License: Apache-2.0 Imports: 10 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitLogger

func InitLogger(cfg *Config) error

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

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"`
	// 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 (Logger) ErrorFilterContextCanceled added in v1.0.3

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