logutil

package
v1.1.0-beta.0...-cc83417 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 24 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
	// DefaultSlowTxnThreshold is the default slow txn log threshold in ms.
	DefaultSlowTxnThreshold = 0
	// DefaultQueryLogMaxLen is the default max length of the query in the log.
	DefaultQueryLogMaxLen = 4096
	// DefaultRecordPlanInSlowLog is the default value for whether enable log query plan in the slow log.
	DefaultRecordPlanInSlowLog = 1
	// DefaultTiDBEnableSlowLog enables TiDB to log slow queries.
	DefaultTiDBEnableSlowLog = true
)
View Source
const (
	// LogFieldCategory is the field name for log category
	LogFieldCategory = "category"
	// LogFieldConn is the field name for connection id in log
	LogFieldConn = "conn"
	// LogFieldSessionAlias is the field name for session_alias in log
	LogFieldSessionAlias = "session_alias"
)
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"

	// GRPCDebugEnvName is the environment variable name for GRPC_DEBUG.
	GRPCDebugEnvName = "GRPC_DEBUG"
)
View Source
const TraceEventKey = "event"

TraceEventKey presents the TraceEventKey in span log.

Variables

View Source
var CtxLogKey = ctxLogKeyType{}

CtxLogKey indicates the context key for logger public for test usage.

View Source
var EmptyFileLogConfig = FileLogConfig{}

EmptyFileLogConfig is an empty FileLogConfig.

View Source
var GeneralLogger = log.L()

GeneralLogger is used to log general log, InitLogger will modify it according to config file.

View Source
var SlowQueryLogger = log.L()

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

Functions

func BgLogger

func BgLogger() *zap.Logger

BgLogger is alias of `logutil.BgLogger()`. It's initialized in tidb-server's main function. Don't use it in `init` or equivalent functions otherwise it will print to stdout.

func ErrVerboseLogger

func ErrVerboseLogger() *zap.Logger

ErrVerboseLogger returns a logger that always output error verbose regardless of the log config. error verbose is disabled on default, but without stack it's harder to investigate some issues, such as in DXF the error mostly happen in business logic, the error stack is very deep, we want to log the stack to help us investigate. Note: if stack is not that needed to investigate, use normal logger instead.

func Event

func Event(ctx context.Context, event string)

Event records event in current tracing span.

func Eventf

func Eventf(ctx context.Context, format string, args ...any)

Eventf records event in current tracing span with format support.

func Hex

func Hex(msg proto.Message) fmt.Stringer

Hex defines a fmt.Stringer for proto.Message. We can't define the String() method on proto.Message, but we can wrap it.

func InitLogger

func InitLogger(cfg *LogConfig, opts ...zap.Option) error

InitLogger initializes a logger with cfg.

func LogEnvVariables

func LogEnvVariables()

LogEnvVariables logs related environment variables.

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 LoggerWithTraceInfo

func LoggerWithTraceInfo(logger *zap.Logger, info *model.TraceInfo) *zap.Logger

LoggerWithTraceInfo attaches fields from trace info to logger

func ReplaceLogger

func ReplaceLogger(cfg *LogConfig, opts ...zap.Option) error

ReplaceLogger replace global logger instance with given log config.

func SampleLoggerFactory

func SampleLoggerFactory(tick time.Duration, first int, fields ...zap.Field) func() *zap.Logger

SampleLoggerFactory returns a factory function that creates a sample logger. the logger is used to sample the log to avoid too many logs, it will only log the first 'first' log entries with the same level and message in 'tick' time. NOTE: Because we need to record the log count with the same level and message in this specific logger, the returned factory function will only create one logger. this logger support at most 4096 types of logs with the same level and message.

func SetLevel

func SetLevel(level string) error

SetLevel sets the zap logger's level.

func SetTag

func SetTag(ctx context.Context, key string, value any)

SetTag sets tag kv-pair in current tracing span

func WithCategory

func WithCategory(ctx context.Context, category string) context.Context

WithCategory attaches category to context.

func WithConnID

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

WithConnID attaches connId to context.

func WithFields

func WithFields(ctx context.Context, fields ...zap.Field) context.Context

WithFields attaches key/value to context.

func WithKeyValue

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

WithKeyValue attaches key/value to context.

func WithSessionAlias

func WithSessionAlias(ctx context.Context, alias string) context.Context

WithSessionAlias attaches session_alias to context

func WithTraceFields

func WithTraceFields(ctx context.Context, info *model.TraceInfo) context.Context

WithTraceFields attaches trace fields to context

func WithTraceLogger

func WithTraceLogger(ctx context.Context, info *model.TraceInfo) context.Context

WithTraceLogger attaches trace identifier to context

Types

type FileLogConfig

type FileLogConfig struct {
	log.FileLogConfig
}

FileLogConfig serializes file log related config in toml/json.

func NewFileLogConfig

func NewFileLogConfig(maxSize uint) FileLogConfig

NewFileLogConfig creates a FileLogConfig.

type LogConfig

type LogConfig struct {
	log.Config

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

	// GeneralLogFile filenanme, default to File log config on empty.
	GeneralLogFile string
}

LogConfig serializes log related config in toml/json.

func NewLogConfig

func NewLogConfig(level, format, slowQueryFile string, generalLogFile string, fileCfg FileLogConfig, disableTimestamp bool, opts ...func(*log.Config)) *LogConfig

NewLogConfig creates a LogConfig.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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