log: github.com/pingcap/log Index | Files

package log

import "github.com/pingcap/log"

Index

Package Files

config.go global.go log.go zap_text_core.go zap_text_encoder.go

Variables

var (

    // Get retrieves a buffer from the pool, creating one if necessary.
    Get = _pool.Get
)

func Debug Uses

func Debug(msg string, fields ...zap.Field)

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 Uses

func DefaultTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)

DefaultTimeEncoder serializes time.Time to a human-readable formatted string

func Error Uses

func Error(msg string, fields ...zap.Field)

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 Uses

func Fatal(msg string, fields ...zap.Field)

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 GetLevel Uses

func GetLevel() zapcore.Level

GetLevel gets the logging level.

func Info Uses

func Info(msg string, fields ...zap.Field)

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 Uses

func L() *zap.Logger

L returns the global Logger, which can be reconfigured with ReplaceGlobals. It's safe for concurrent use.

func NewTextCore Uses

func NewTextCore(enc *textEncoder, ws zapcore.WriteSyncer, enab zapcore.LevelEnabler) zapcore.Core

NewTextCore creates a Core that writes logs to a WriteSyncer.

func NewTextEncoder Uses

func NewTextEncoder(cfg *Config) zapcore.Encoder

NewTextEncoder creates a fast, low-allocation Text encoder. The encoder appropriately escapes all field keys and values.

func Panic Uses

func Panic(msg string, fields ...zap.Field)

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 Uses

func ReplaceGlobals(logger *zap.Logger, props *ZapProperties)

ReplaceGlobals replaces the global Logger and SugaredLogger. It's unsafe for concurrent use.

func S Uses

func S() *zap.SugaredLogger

S returns the global SugaredLogger, which can be reconfigured with ReplaceGlobals. It's safe for concurrent use.

func SetLevel Uses

func SetLevel(l zapcore.Level)

SetLevel alters the logging level.

func ShortCallerEncoder Uses

func ShortCallerEncoder(caller zapcore.EntryCaller, enc zapcore.PrimitiveArrayEncoder)

ShortCallerEncoder serializes a caller in file:line format.

func Sync Uses

func Sync() error

Sync flushes any buffered log entries.

func Warn Uses

func Warn(msg string, fields ...zap.Field)

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.

type Config Uses

type Config struct {
    // Log level.
    Level string `toml:"level" json:"level"`
    // Log format. one of json, text, or console.
    Format string `toml:"format" json:"format"`
    // Disable automatic timestamps in output.
    DisableTimestamp bool `toml:"disable-timestamp" json:"disable-timestamp"`
    // File log config.
    File FileLogConfig `toml:"file" json:"file"`
    // Development puts the logger in development mode, which changes the
    // behavior of DPanicLevel and takes stacktraces more liberally.
    Development bool `toml:"development" json:"development"`
    // DisableCaller stops annotating logs with the calling function's file
    // name and line number. By default, all logs are annotated.
    DisableCaller bool `toml:"disable-caller" json:"disable-caller"`
    // 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 `toml:"disable-stacktrace" json:"disable-stacktrace"`
    // DisableErrorVerbose stops annotating logs with the full verbose error
    // message.
    DisableErrorVerbose bool `toml:"disable-error-verbose" json:"disable-error-verbose"`
    // 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 `toml:"sampling" json:"sampling"`
}

Config serializes log related config in toml/json.

type FileLogConfig Uses

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"`
}

FileLogConfig serializes file log related config in toml/json.

type ZapProperties Uses

type ZapProperties struct {
    Core   zapcore.Core
    Syncer zapcore.WriteSyncer
    Level  zap.AtomicLevel
}

ZapProperties records some information about zap.

func InitLogger Uses

func InitLogger(cfg *Config, opts ...zap.Option) (*zap.Logger, *ZapProperties, error)

InitLogger initializes a zap logger.

func InitLoggerWithWriteSyncer Uses

func InitLoggerWithWriteSyncer(cfg *Config, output zapcore.WriteSyncer, opts ...zap.Option) (*zap.Logger, *ZapProperties, error)

InitLoggerWithWriteSyncer initializes a zap logger with specified write syncer.

Package log imports 14 packages (graph) and is imported by 61 packages. Updated 2019-10-15. Refresh now. Tools for package owners.