Documentation ¶
Index ¶
- func InitLogger(cfg *Config, _ string) error
- func IsContextCanceledError(err error) bool
- func Level() zapcore.Level
- func NewContext(ctx context.Context, logger Logger) context.Context
- func SetAppLogger(l *zap.Logger)
- func SetLevel(level zapcore.Level) zapcore.Level
- func ShortError(err error) zap.Field
- type Config
- type FilterCore
- type Logger
- type Task
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InitLogger ¶
InitLogger initializes Lightning's and also the TiDB library's loggers.
func IsContextCanceledError ¶
IsContextCanceledError returns whether the error is caused by context cancellation.
func NewContext ¶
NewContext returns a new context with the provided logger.
func SetAppLogger ¶
SetAppLogger replaces the default logger in this package to given one
func ShortError ¶
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.
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"` // EnableDiagnoseLogs, when enabled, we will output logs from all packages and enable GRPC debug log. EnableDiagnoseLogs bool `toml:"enable-diagnose-logs" json:"enable-diagnose-logs"` }
Config serializes log related config in toml/json.
type FilterCore ¶
FilterCore is a zapcore.Core implementation, it filters log by path-qualified package name.
func NewFilterCore ¶
func NewFilterCore(core zapcore.Core, allowPackages ...string) *FilterCore
NewFilterCore returns a FilterCore, only logs under allowPackages will be written.
Example, only write br's log and ignore any other, `NewFilterCore(core, "github.com/pingcap/tidb/br/")`. Note, must set AddCaller() to the logger.
func (*FilterCore) Check ¶
func (f *FilterCore) Check(entry zapcore.Entry, ce *zapcore.CheckedEntry) *zapcore.CheckedEntry
Check overrides wrapper core.Check and adds itself to zapcore.CheckedEntry.
type Logger ¶
Logger is a simple wrapper around *zap.Logger which provides some extra methods to simplify Lightning's log usage.
func FromContext ¶
FromContext returns the logger stored in the context.
func MakeTestLogger ¶
MakeTestLogger creates a Logger instance which produces JSON logs.
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.