zap

package
v0.0.0-...-b81e666 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ConsoleZapCore = "console"
	FileZapCore    = "file"
)

Some ZapCore constants.

Variables

View Source
var (
	Levels = map[string]zapcore.Level{
		"":      zapcore.DebugLevel,
		"trace": zapcore.DebugLevel,
		"debug": zapcore.DebugLevel,
		"info":  zapcore.InfoLevel,
		"warn":  zapcore.WarnLevel,
		"error": zapcore.ErrorLevel,
		"fatal": zapcore.FatalLevel,
		"panic": zapcore.PanicLevel,
	}
)

Functions

func CustomTimeFormat

func CustomTimeFormat(t time.Time, format string) string

CustomTimeFormat customize time format. Deprecated: Use https://pkg.go.dev/time#Time.Format instead.

func DefaultTimeFormat

func DefaultTimeFormat(t time.Time) []byte

DefaultTimeFormat returns the default time format "2006-01-02 15:04:05.000". Deprecated: Use https://pkg.go.dev/time#Time.AppendFormat instead.

func GetLogEncoderKey

func GetLogEncoderKey(defKey, key string) string

GetLogEncoderKey gets user defined log output name, uses defKey if empty.

func NewTimeEncoder

func NewTimeEncoder(format string) zapcore.TimeEncoder

NewTimeEncoder creates a time format encoder.

func NewZapLog

func NewZapLog(c xlog.Config) xlog.Logger

NewZapLog creates a zap Logger object whose caller skip is set to 2.

func NewZapLogWithCallerSkip

func NewZapLogWithCallerSkip(cfg xlog.Config, callerSkip int) xlog.Logger

NewZapLogWithCallerSkip creates a default Logger from zap.

func RedirectStdLog

func RedirectStdLog(logger xlog.Logger) (func(), error)

RedirectStdLog redirects std log to trpc logger as log level INFO. After redirection, log flag is zero, the prefix is empty. The returned function may be used to recover log flag and prefix, and redirect output to os.Stderr.

func RedirectStdLogAt

func RedirectStdLogAt(logger xlog.Logger, level zapcore.Level) (func(), error)

RedirectStdLogAt redirects std log to trpc logger with a specific level. After redirection, log flag is zero, the prefix is empty. The returned function may be used to recover log flag and prefix, and redirect output to os.Stderr.

Types

type ConsoleWriterFactory

type ConsoleWriterFactory struct {
}

ConsoleWriterFactory is the console writer instance.

func (*ConsoleWriterFactory) Setup

func (f *ConsoleWriterFactory) Setup(name string, dec plugin.Decoder) error

Setup starts, loads and registers console output writer.

func (*ConsoleWriterFactory) Type

func (f *ConsoleWriterFactory) Type() string

Type returns the log plugin type.

type Decoder

type Decoder struct {
	OutputConfig *xlog.OutputConfig
	Core         zapcore.Core
	ZapLevel     zap.AtomicLevel
}

Decoder decodes the log.

func (*Decoder) Decode

func (d *Decoder) Decode(cfg interface{}) error

Decode decodes writer configuration, copy one.

type Factory

type Factory struct{}

Factory is the log plugin factory. When server start, the configuration is feed to Factory to generate a log instance.

func (*Factory) Setup

func (f *Factory) Setup(name string, dec plugin.Decoder) error

Setup starts, load and register logs.

func (*Factory) Type

func (f *Factory) Type() string

Type returns the log plugin type.

type FileWriterFactory

type FileWriterFactory struct {
}

FileWriterFactory is the file writer instance Factory.

func (*FileWriterFactory) Setup

func (f *FileWriterFactory) Setup(name string, dec plugin.Decoder) error

Setup starts, loads and register file output writer.

func (*FileWriterFactory) Type

func (f *FileWriterFactory) Type() string

Type returns log file type.

Jump to

Keyboard shortcuts

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