Documentation ¶
Index ¶
- Variables
- func Debug(msg string, fields ...zap.Field)
- func DebugCtx(ctx context.Context, msg string, fields ...zap.Field)
- func DefaultTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)
- func Error(msg string, fields ...zap.Field)
- func ErrorCtx(ctx context.Context, msg string, fields ...zap.Field)
- func Fatal(msg string, fields ...zap.Field)
- func GetLevel() zapcore.Level
- func Info(msg string, fields ...zap.Field)
- func InfoCtx(ctx context.Context, msg string, fields ...zap.Field)
- func L() *zap.Logger
- func LockWithTimeout(ws zapcore.WriteSyncer, timeout int) zapcore.WriteSyncer
- func NewTextCore(enc zapcore.Encoder, ws zapcore.WriteSyncer, enab zapcore.LevelEnabler) zapcore.Core
- func NewTextEncoder(cfg *Config) (zapcore.Encoder, error)
- func Panic(msg string, fields ...zap.Field)
- func PanicCtx(ctx context.Context, msg string, fields ...zap.Field)
- func ReplaceGlobals(logger *zap.Logger, props *ZapProperties) func()
- func S() *zap.SugaredLogger
- func SetLevel(l zapcore.Level)
- func ShortCallerEncoder(caller zapcore.EntryCaller, enc zapcore.PrimitiveArrayEncoder)
- func Sync() error
- func Warn(msg string, fields ...zap.Field)
- func WarnCtx(ctx context.Context, msg string, fields ...zap.Field)
- func With(fields ...zap.Field) *zap.Loggerdeprecated
- type Config
- type FileLogConfig
- type TextIOCore
- func (c *TextIOCore) Check(ent zapcore.Entry, ce *zapcore.CheckedEntry) *zapcore.CheckedEntry
- func (c *TextIOCore) Clone() *TextIOCore
- func (c *TextIOCore) Sync() error
- func (c *TextIOCore) With(fields []zapcore.Field) zapcore.Core
- func (c *TextIOCore) Write(ent zapcore.Entry, fields []zapcore.Field) error
- type ZapProperties
- func InitLogger(cfg *Config, opts ...zap.Option) (*zap.Logger, *ZapProperties, error)
- func InitLoggerWithWriteSyncer(cfg *Config, output, errOutput zapcore.WriteSyncer, opts ...zap.Option) (*zap.Logger, *ZapProperties, error)
- func InitTestLogger(t zaptest.TestingT, cfg *Config, opts ...zap.Option) (*zap.Logger, *ZapProperties, error)
Constants ¶
This section is empty.
Variables ¶
var (
// Get retrieves a buffer from the pool, creating one if necessary.
Get = _pool.Get
)
var ZapEncodingName = "zlog"
ZapEncodingName is the encoder name registered in zap
Functions ¶
func Debug ¶
Debug logs a message at DebugLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
func DefaultTimeEncoder ¶
func DefaultTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)
DefaultTimeEncoder serializes time.Time to a human-readable formatted string
func Error ¶
Error logs a message at ErrorLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
func Fatal ¶
Fatal logs a message at FatalLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
The logger then calls os.Exit(1), even if logging at FatalLevel is disabled.
func Info ¶
Info logs a message at InfoLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
func L ¶
L returns the global Logger, which can be reconfigured with ReplaceGlobals. It's safe for concurrent use.
func LockWithTimeout ¶
func LockWithTimeout(ws zapcore.WriteSyncer, timeout int) zapcore.WriteSyncer
LockWithTimeout wraps a WriteSyncer make it safe for concurrent use, just like zapcore.Lock() timeout seconds.
func NewTextCore ¶
func NewTextCore(enc zapcore.Encoder, ws zapcore.WriteSyncer, enab zapcore.LevelEnabler) zapcore.Core
NewTextCore creates a Core that writes logs to a WriteSyncer.
func NewTextEncoder ¶
NewTextEncoder creates a fast, low-allocation Text encoder. The encoder appropriately escapes all field keys and values.
func Panic ¶
Panic logs a message at PanicLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
The logger then panics, even if logging at PanicLevel is disabled.
func ReplaceGlobals ¶
func ReplaceGlobals(logger *zap.Logger, props *ZapProperties) func()
ReplaceGlobals replaces the global Logger and SugaredLogger, and returns a function to restore the original values. It's safe for concurrent use.
func S ¶
func S() *zap.SugaredLogger
S returns the global SugaredLogger, which can be reconfigured with ReplaceGlobals. It's safe for concurrent use.
func ShortCallerEncoder ¶
func ShortCallerEncoder(caller zapcore.EntryCaller, enc zapcore.PrimitiveArrayEncoder)
ShortCallerEncoder serializes a caller in file:line format.
func Warn ¶
Warn logs a message at WarnLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.
func With
deprecated
With creates a child logger and adds structured context to it. Fields added to the child don't affect the parent, and vice versa.
Deprecated: With should not add caller skip, since it's not a logging function. Please use log.L().With instead. With is kept for compatibility. See https://github.com/pingcap/log/issues/32 for more details.
Types ¶
type Config ¶
type Config struct { // Enable std log DisableStdlog bool `toml:"disable-stdlog" json:"disable-stdlog"` // Log level. Level string `toml:"level" json:"level" mapstructure:"level"` // Log format. One of json or text. Format string `toml:"format" json:"format" mapstructure:"format"` // Disable automatic timestamps in output. DisableTimestamp bool `json:"-"` // File log config. File FileLogConfig `toml:"file" json:"file" mapstructure:"file"` // Development puts the logger in development mode, which changes the // behavior of DPanicLevel and takes stacktraces more liberally. Development bool `json:"-"` // DisableCaller stops annotating logs with the calling function's file // name and line number. By default, all logs are annotated. DisableCaller bool `json:"-"` // DisableStacktrace completely disables automatic stacktrace capturing. By // default, stacktraces are captured for WarnLevel and above logs in // development and ErrorLevel and above in production. DisableStacktrace bool `json:"-"` // DisableErrorVerbose stops annotating logs with the full verbose error // message. DisableErrorVerbose bool `json:"-"` // SamplingConfig sets a sampling strategy for the logger. Sampling caps the // global CPU and I/O load that logging puts on your process while attempting // to preserve a representative subset of your logs. // // Values configured here are per-second. See zapcore.NewSampler for details. Sampling *zap.SamplingConfig `json:"-"` // ErrorOutputPath is a path to write internal logger errors to. // If this field is not set, the internal logger errors will be sent to the same file as in File field. // Note: if we want to output the logger errors to stderr, we can just set this field to "stderr" ErrorOutputPath string `json:"-"` // Timeout for writing log, if TiDB hang on writing log, make it panic. // The value is seconds, 0 means no timeout Timeout int `json:"-"` }
Config serializes log related config in toml/json.
type FileLogConfig ¶
type FileLogConfig struct { // Log filename, leave empty to disable file log. Filename string `toml:"filename" json:"filename"` // Max size for a single file, in MB. MaxSize int `toml:"max-size" json:"max-size"` // Max log keep days, default is never deleting. MaxDays int `toml:"max-days" json:"max-days"` // Maximum number of old log files to retain. MaxBackups int `toml:"max-backups" json:"max-backups"` // Compression function for rotated files. // Currently only `gzip` and empty are supported, empty means compression disabled. Compression string `toml:"compression" json:"compression"` }
FileLogConfig serializes file log related config in toml/json.
type TextIOCore ¶
type TextIOCore struct { zapcore.LevelEnabler // contains filtered or unexported fields }
TextIOCore is a copy of zapcore.ioCore that only accept *textEncoder it can be removed after https://github.com/uber-go/zap/pull/685 be merged
func (*TextIOCore) Check ¶
func (c *TextIOCore) Check(ent zapcore.Entry, ce *zapcore.CheckedEntry) *zapcore.CheckedEntry
func (*TextIOCore) Clone ¶
func (c *TextIOCore) Clone() *TextIOCore
func (*TextIOCore) Sync ¶
func (c *TextIOCore) Sync() error
type ZapProperties ¶
type ZapProperties struct { Core zapcore.Core Syncer zapcore.WriteSyncer Level zap.AtomicLevel }
ZapProperties records some information about zap.
func InitLogger ¶
InitLogger initializes a zap logger.
func InitLoggerWithWriteSyncer ¶
func InitLoggerWithWriteSyncer(cfg *Config, output, errOutput zapcore.WriteSyncer, opts ...zap.Option) (*zap.Logger, *ZapProperties, error)
InitLoggerWithWriteSyncer initializes a zap logger with specified write syncer.