log

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DebugLevel = zapcore.DebugLevel
	InfoLevel  = zapcore.InfoLevel
	WarnLevel  = zapcore.WarnLevel
	ErrorLevel = zapcore.ErrorLevel
	PanicLevel = zapcore.PanicLevel
	FatalLevel = zapcore.FatalLevel
)
View Source
var (
	Any         = zap.Any
	Array       = zap.Array
	Object      = zap.Object
	Binary      = zap.Binary
	Bool        = zap.Bool
	Bools       = zap.Bools
	ByteString  = zap.ByteString
	ByteStrings = zap.ByteStrings
	Complex64   = zap.Complex64
	Complex64s  = zap.Complex64s
	Complex128  = zap.Complex128
	Complex128s = zap.Complex128s
	Duration    = zap.Duration
	Durations   = zap.Durations
	Err         = zap.Error
	Errors      = zap.Errors
	Float32     = zap.Float32
	Float32s    = zap.Float32s
	Float64     = zap.Float64
	Float64s    = zap.Float64s
	Int         = zap.Int
	Ints        = zap.Ints
	Int8        = zap.Int8
	Int8s       = zap.Int8s
	Int16       = zap.Int16
	Int16s      = zap.Int16s
	Int32       = zap.Int32
	Int32s      = zap.Int32s
	Int64       = zap.Int64
	Int64s      = zap.Int64s
	Namespace   = zap.Namespace
	Reflect     = zap.Reflect
	Stack       = zap.Stack
	String      = zap.String
	Stringer    = zap.Stringer
	Strings     = zap.Strings
	Time        = zap.Time
	Times       = zap.Times
	Uint        = zap.Uint
	Uints       = zap.Uints
	Uint8       = zap.Uint8
	Uint8s      = zap.Uint8s
	Uint16      = zap.Uint16
	Uint16s     = zap.Uint16s
	Uint32      = zap.Uint32
	Uint32s     = zap.Uint32s
	Uint64      = zap.Uint64
	Uint64s     = zap.Uint64s
	Uintptr     = zap.Uintptr
	Uintptrs    = zap.Uintptrs
)

Alias for zap type functions.

Functions

func Debug

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

Debug method output debug level log.

func Debugf

func Debugf(format string, v ...interface{})

Debugf method output debug level log.

func Debugw

func Debugw(msg string, keysAndValues ...interface{})

Debugw method output debug level log.

func Error

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

Error method output error level log.

func ErrorR

func ErrorR(format string, v ...interface{}) error

func Errorf

func Errorf(format string, v ...interface{})

Errorf method output error level log.

func Errorw

func Errorw(msg string, keysAndValues ...interface{})

Errorw method output error level log.

func Fatal

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

Fatal method output fatal level log.

func Fatalf

func Fatalf(format string, v ...interface{})

Fatalf method output fatal level log.

func Fatalw

func Fatalw(msg string, keysAndValues ...interface{})

Fatalw method output Fatalw level log.

func Flush

func Flush()

Flush calls the underlying Core's Sync method, flushing any buffered log entries. Applications should take care to call Sync before exiting.

func Info

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

Info method output info level log.

func Infof

func Infof(format string, v ...interface{})

Infof method output info level log.

func Infow

func Infow(msg string, keysAndValues ...interface{})

Infow method output info level log.

func Init

func Init(level, format string)

init logger. level should be one of "debug", "info", "warn", "error", "panic", "fatal", format should be oneof "console","json"

func Panic

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

Panic method output panic level log and shutdown application.

func Panicf

func Panicf(format string, v ...interface{})

Panicf method output panic level log and shutdown application.

func Panicw

func Panicw(msg string, keysAndValues ...interface{})

Panicw method output panic level log.

func Warn

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

Warn method output warning level log.

func Warnf

func Warnf(format string, v ...interface{})

Warnf method output warning level log.

func Warnw

func Warnw(msg string, keysAndValues ...interface{})

Warnw method output warning level log.

Types

type Field

type Field = zapcore.Field

type Level

type Level = zapcore.Level

type Logger

type Logger interface {
	// info level
	Info(msg string, fields ...Field)
	Infof(format string, v ...interface{})
	Infow(msg string, keysAndValues ...interface{})
	// debug level
	Debug(msg string, fields ...Field)
	Debugf(format string, v ...interface{})
	Debugw(msg string, keysAndValues ...interface{})
	// warn level
	Warn(msg string, fields ...Field)
	Warnf(format string, v ...interface{})
	Warnw(msg string, keysAndValues ...interface{})
	// error level
	Error(msg string, fields ...Field)
	Errorf(format string, v ...interface{})
	Errorw(msg string, keysAndValues ...interface{})
	ErrorR(format string, v ...interface{}) error
	// panic level
	Panic(msg string, fields ...Field)
	Panicf(format string, v ...interface{})
	Panicw(msg string, keysAndValues ...interface{})
	// fatal level
	Fatal(msg string, fields ...Field)
	Fatalf(format string, v ...interface{})
	Fatalw(msg string, keysAndValues ...interface{})

	// WithValues adds some key-value pairs of context to a logger.
	WithValues(keysAndValues ...interface{}) Logger

	// WithName adds a new element to the logger's name.
	// Successive calls with WithName continue to append
	// suffixes to the logger's name.  It's strongly recommended
	// that name segments contain only letters, digits, and hyphens
	// (see the package documentation for more information).
	WithName(name string) Logger

	// Flush calls the underlying Core's Sync method, flushing any buffered
	// log entries. Applications should take care to call Sync before exiting.
	Flush()
}

Logger represents the ability to log messages, both errcode and not.

func NewNopLogger

func NewNopLogger() Logger

NewNopLogger returns a logger that doesn't do anything.

func WithName

func WithName(s string) Logger

WithName adds a new path segment to the logger's name. Segments are joined by periods. By default, Loggers are unnamed.

func WithValues

func WithValues(keysAndValues ...interface{}) Logger

WithValues creates a child logger and adds adds Zap fields to it.

type Options

type Options struct {
	// destination of log
	OutputPaths []string `json:"output-paths"`
	// the error log of zap
	ErrorOutputPaths []string `json:"error-output-paths"`
	// log level  "info debug warn error panic fatal"
	Level string `json:"level"`
	// json or console
	Format string `json:"format"`
	// show file, function, line number in log
	DisableCaller     bool `json:"disable-caller"`
	DisableStacktrace bool `json:"disable-stacktrace"`
	// console format can enable color
	EnableColor bool   `json:"enable-color"`
	Development bool   `json:"development"`
	Name        string `json:"name"`
}

options for create log

func NewOptions

func NewOptions() *Options

func (*Options) Validate

func (opt *Options) Validate() error

type ZapLogger

type ZapLogger struct {
	// contains filtered or unexported fields
}

func New

func New(opts *Options) *ZapLogger

New create logger by opts which can customized by command arguments.

func (*ZapLogger) Debug

func (l *ZapLogger) Debug(msg string, fields ...Field)

func (*ZapLogger) Debugf

func (l *ZapLogger) Debugf(format string, v ...interface{})

func (*ZapLogger) Debugw

func (l *ZapLogger) Debugw(msg string, keysAndValues ...interface{})

func (*ZapLogger) Error

func (l *ZapLogger) Error(msg string, fields ...Field)

func (*ZapLogger) ErrorR

func (l *ZapLogger) ErrorR(format string, v ...interface{}) error

func (*ZapLogger) Errorf

func (l *ZapLogger) Errorf(format string, v ...interface{})

func (*ZapLogger) Errorw

func (l *ZapLogger) Errorw(msg string, keysAndValues ...interface{})

func (*ZapLogger) Fatal

func (l *ZapLogger) Fatal(msg string, fields ...Field)

func (*ZapLogger) Fatalf

func (l *ZapLogger) Fatalf(format string, v ...interface{})

func (*ZapLogger) Fatalw

func (l *ZapLogger) Fatalw(msg string, keysAndValues ...interface{})

func (*ZapLogger) Flush

func (l *ZapLogger) Flush()

func (*ZapLogger) Info

func (l *ZapLogger) Info(msg string, fields ...Field)

func (*ZapLogger) Infof

func (l *ZapLogger) Infof(format string, v ...interface{})

func (*ZapLogger) Infow

func (l *ZapLogger) Infow(msg string, keysAndValues ...interface{})

func (*ZapLogger) Panic

func (l *ZapLogger) Panic(msg string, fields ...Field)

func (*ZapLogger) Panicf

func (l *ZapLogger) Panicf(format string, v ...interface{})

func (*ZapLogger) Panicw

func (l *ZapLogger) Panicw(msg string, keysAndValues ...interface{})

func (*ZapLogger) Warn

func (l *ZapLogger) Warn(msg string, fields ...Field)

func (*ZapLogger) Warnf

func (l *ZapLogger) Warnf(format string, v ...interface{})

func (*ZapLogger) Warnw

func (l *ZapLogger) Warnw(msg string, keysAndValues ...interface{})

func (*ZapLogger) WithName

func (l *ZapLogger) WithName(name string) Logger

func (*ZapLogger) WithValues

func (l *ZapLogger) WithValues(keysAndValues ...interface{}) Logger

Jump to

Keyboard shortcuts

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