Documentation ¶
Index ¶
- func AppendZapFieldToCtx(ctx context.Context, newFields ...zap.Field) context.Context
- func InitLogger(cfg *Config) error
- func IsRedactLogEnabled() bool
- func Props() *pclog.ZapProperties
- func RedactString(arg string) string
- func SetLevel(level zapcore.Level) zapcore.Level
- func SetRedactLog(enabled bool)
- func ShortError(err error) zap.Field
- func WrapStringerField(message string, object fmt.Stringer) zap.Field
- func ZapRedactString(key, arg string) zap.Field
- type Config
- type Logger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendZapFieldToCtx ¶
AppendZapFieldToCtx attaches new fields to the context, which can be then used with log.WithCtx().
func InitLogger ¶
InitLogger initializes DM's and also the TiDB library's loggers.
func IsRedactLogEnabled ¶
func IsRedactLogEnabled() bool
IsRedactLogEnabled indicates whether the log desensitization is enabled.
func RedactString ¶
RedactString receives string 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 DM, 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 WrapStringerField ¶
WrapStringerField returns a wrap stringer field.
func ZapRedactString ¶
ZapRedactString receives string 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"` // the format of the log, "text" or "json" Format string `toml:"format" json:"format"` // 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 Logger ¶
Logger is a simple wrapper around *zap.Logger which provides some extra methods to simplify DM's log usage.
func (Logger) ErrorFilterContextCanceled ¶
ErrorFilterContextCanceled wraps Logger.Error() and will filter error log when error is context.Canceled.