log

package
v4.0.10+incompatible Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitLogger

func InitLogger(cfg *Config, tidbLoglevel string) error

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

func InitRedact

func InitRedact(redactLog bool)

InitRedact inits the enableRedactLog

func IsContextCanceledError

func IsContextCanceledError(err error) bool

IsContextCanceledError returns whether the error is caused by context cancellation.

func Level

func Level() zapcore.Level

Level returns the current global log level.

func NeedRedact

func NeedRedact() bool

NeedRedact returns whether to redact log

func RedactString

func RedactString(arg string) string

RedactString receives string argument and return omitted information if redact log enabled

func RedactStringer

func RedactStringer(arg fmt.Stringer) fmt.Stringer

RedactStringer receives stringer argument and return omitted information if redact log enabled

func SetAppLogger

func SetAppLogger(l *zap.Logger)

SetAppLogger replaces the default logger in this package to given one

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 Lightning, 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 ZapRedactArray

func ZapRedactArray(key string, val zapcore.ArrayMarshaler) zapcore.Field

ZapRedactArray receives zap.Array and return omitted information if redact log enabled

func ZapRedactBinary

func ZapRedactBinary(key string, val []byte) zapcore.Field

ZapRedactBinary receives zap.Binary and return omitted information if redact log enabled

func ZapRedactReflect

func ZapRedactReflect(key string, val interface{}) zapcore.Field

ZapRedactReflect receives zap.Reflect and return omitted information if redact log enabled

func ZapRedactString

func ZapRedactString(key string, arg string) zap.Field

ZapRedactString receives stringer argument and return omitted information in zap.Field if redact log enabled

func ZapRedactStringer

func ZapRedactStringer(key string, arg fmt.Stringer) zap.Field

ZapRedactStringer receives stringer argument and return omitted information in zap.Field if redact log enabled

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()

type Logger

type Logger struct {
	*zap.Logger
}

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

func L

func L() Logger

L returns the current logger for Lightning.

func MakeTestLogger

func MakeTestLogger() (Logger, *zaptest.Buffer)

MakeTestLogger creates a Logger instance which produces JSON logs.

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) Begin

func (logger Logger) Begin(level zapcore.Level, name string) *Task

Begin marks the beginning of a task.

func (Logger) Named

func (logger Logger) Named(name string) Logger

Named adds a new path segment to the logger's name.

func (Logger) With

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

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

type Task

type Task struct {
	Logger
	// contains filtered or unexported fields
}

Task is a logger for a task spanning a period of time. This structure records when the task is started, so the time elapsed for the whole task can be logged without book-keeping.

func (*Task) End

func (task *Task) End(level zapcore.Level, err error, extraFields ...zap.Field) time.Duration

End marks the end of a task.

The `level` is the log level if the task *failed* (i.e. `err != nil`). If the task *succeeded* (i.e. `err == nil`), the level from `Begin()` is used instead.

The `extraFields` are included in the log only when the task succeeded.

Jump to

Keyboard shortcuts

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