zaputil

package
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 17, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultLogTimeFormat = "2006-01-02T15:04:05.000000Z07:00"

Variables

View Source
var (

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

Functions

func DefaultDurationEncoder

func DefaultDurationEncoder(d time.Duration, enc zapcore.PrimitiveArrayEncoder)

func DefaultTimeEncoder

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

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

func NewTextCore

NewTextCore creates a Core that writes logs to a WriteSyncer.

func NewTextEncoder

func NewTextEncoder(cfg *Config) zapcore.Encoder

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

func ShortCallerEncoder

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

ShortCallerEncoder serializes a caller in file:line format.

Types

type Config

type Config struct {
	// Log level.
	Level zapcore.Level `toml:"level"`
	// Log format. one of json, text, or console.
	Format string `toml:"format"`
	// Disable automatic timestamps in output.
	DisableTimestamp bool `toml:"disable-timestamp"`
	// File log config.
	File FileConfig `toml:"file"`
	// Development puts the logger in development mode, which changes the
	// behavior of DPanicLevel and takes stacktraces more liberally.
	Development bool `toml:"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"`
	// 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"`
	// DisableErrorVerbose stops annotating logs with the full verbose error
	// message.
	DisableErrorVerbose bool `toml:"disable-error-verbose"`
}

Config "comment"

type FileConfig

type FileConfig struct {
	// Log filename, leave empty to disable file log.
	Filename string `toml:"filename"`
	// Max size for a single file, in MB.
	MaxSize int `toml:"max-size"`
	// Max log keep days, default is never deleting.
	MaxDays int `toml:"max-days"`
	// Maximum number of old log files to retain.
	MaxBackups int `toml:"max-backups"`
}

FileConfig "comment"

type ZapProperties

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

ZapProperties records some information about zap.

func InitLogger

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

InitLogger initializes a zap logger.

func InitLoggerWithWriteSyncer

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

InitLoggerWithWriteSyncer initializes a zap logger with specified write syncer.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL