logutil

package
v0.0.0-...-3633c1a Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (

	// DefaultLogMaxSize is the default size of log files.
	DefaultLogMaxSize = 300 // MB
	// DefaultLogFormat is the default format of the log.
	DefaultLogFormat = "text"

	// DefaultSlowThreshold is the default slow log threshold in millisecond.
	DefaultSlowThreshold = 300
	// DefaultQueryLogMaxLen is the default max length of the query in the log.
	DefaultQueryLogMaxLen = 2048
)
View Source
const (
	// SlowLogTimeFormat is the time format for slow log.
	SlowLogTimeFormat = time.RFC3339Nano
	// OldSlowLogTimeFormat is the first version of the the time format for slow log, This is use for compatibility.
	OldSlowLogTimeFormat = "2006-01-02-15:04:05.999999999 -0700"
)

Variables

View Source
var EmptyFileLogConfig = FileLogConfig{}

EmptyFileLogConfig is an empty FileLogConfig.

View Source
var SlowQueryLogger = log.StandardLogger()

SlowQueryLogger is used to log slow query, InitLogger will modify it according to config file.

View Source
var SlowQueryZapLogger = zaplog.L()

SlowQueryZapLogger is used to log slow query, InitZapLogger will modify it according to config file.

Functions

func BgLogger

func BgLogger() *zap.Logger

BgLogger is alias of `logutil.BgLogger()`

func InitLogger

func InitLogger(cfg *LogConfig) error

InitLogger initializes PD's logger.

func InitZapLogger

func InitZapLogger(cfg *LogConfig) error

InitZapLogger initializes a zap logger with cfg.

func Logger

func Logger(ctx context.Context) *zap.Logger

Logger gets a contextual logger from current context. contextual logger will output common fields from context.

func SetLevel

func SetLevel(level string) error

SetLevel sets the zap logger's level.

func WithConnID

func WithConnID(ctx context.Context, connID uint32) context.Context

WithConnID attaches connId to context.

func WithKeyValue

func WithKeyValue(ctx context.Context, key, value string) context.Context

WithKeyValue attaches key/value to context.

Types

type FileLogConfig

type FileLogConfig struct {
	zaplog.FileLogConfig
}

FileLogConfig serializes file log related config in toml/json.

func NewFileLogConfig

func NewFileLogConfig(rotate bool, maxSize uint) FileLogConfig

NewFileLogConfig creates a FileLogConfig.

type LogConfig

type LogConfig struct {
	zaplog.Config

	// SlowQueryFile filename, default to File log config on empty.
	SlowQueryFile string
}

LogConfig serializes log related config in toml/json.

func NewLogConfig

func NewLogConfig(level, format, slowQueryFile string, fileCfg FileLogConfig, disableTimestamp bool) *LogConfig

NewLogConfig creates a LogConfig.

Jump to

Keyboard shortcuts

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