Documentation ¶
Index ¶
- func InitLogger(cfg *Config, tidbLoglevel string) error
- func InitRedact(redactLog bool)
- func IsContextCanceledError(err error) bool
- func Level() zapcore.Level
- func NeedRedact() bool
- func RedactString(arg string) string
- func RedactStringer(arg fmt.Stringer) fmt.Stringer
- func SetLevel(level zapcore.Level) zapcore.Level
- func ShortError(err error) zap.Field
- func ZapRedactArray(key string, val zapcore.ArrayMarshaler) zapcore.Field
- func ZapRedactBinary(key string, val []byte) zapcore.Field
- func ZapRedactReflect(key string, val interface{}) zapcore.Field
- func ZapRedactString(key string, arg string) zap.Field
- func ZapRedactStringer(key string, arg fmt.Stringer) 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 RedactString ¶
RedactString receives string argument and return omitted information if redact log enabled
func RedactStringer ¶
RedactStringer receives stringer argument and return omitted information if redact log enabled
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.
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 ¶
ZapRedactBinary receives zap.Binary and return omitted information if redact log enabled
func ZapRedactReflect ¶
ZapRedactReflect receives zap.Reflect and return omitted information if redact log enabled
func ZapRedactString ¶
ZapRedactString 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.
type FilterCore ¶
FilterCore is a zapcore.Core implementation, it filters log by path-qualified package name.
func NewFilterCore ¶
func NewFilterCore(core zapcore.Core, filteredPackages ...string) *FilterCore
NewFilterCore returns a FilterCore.
Example, filter TiDB's log, `NewFilterCore(core, "github.com/pingcap/tidb/")`. 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 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.