log

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Any = zap.Any

alias for zap function

Functions

func C

func C(ctx context.Context) *zapLogger

C with context value

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 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 called 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(opts *Options)

func New

func New(opts *Options) *zapLogger

New craetes logger by customized opts

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.

func WithContext

func WithContext(ctx context.Context) context.Context

WithContext returns a copy of context in which the log value is set.

Types

type Field

type Field = zapcore.Field

alias for zap structure

type Level

type Level = zapcore.Level

alias for zap structure

type Logger

type Logger interface {
	Debug(msg string, fields ...Field)
	Debugf(format string, v ...interface{})
	Debugw(msg string, keysAndValues ...interface{})

	Info(msg string, fields ...Field)
	Infof(format string, v ...interface{})
	Infow(msg string, keysAndValues ...interface{})

	Warn(msg string, fields ...Field)
	Warnf(format string, v ...interface{})
	Warnw(msg string, keysAndValues ...interface{})

	Error(msg string, fields ...Field)
	Errorf(format string, v ...interface{})
	Errorw(msg string, keysAndValues ...interface{})

	Panic(msg string, fields ...Field)
	Panicf(format string, v ...interface{})
	Panicw(msg string, keysAndValues ...interface{})

	Fatal(msg string, fields ...Field)
	Fatalf(format string, v ...interface{})
	Fatalw(msg string, keysAndValues ...interface{})

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

	WithName(string) Logger

	// WithContext returns a copy of context in which the log value is set.
	WithContext(ctx context.Context) context.Context

	// flush any buffered log entries. Applications should take care to call Sync before exiting
	Flush()
}

func FromContext

func FromContext(ctx context.Context) Logger

FromContext returns the value of the log key on the ctx

func NewLogger

func NewLogger(l *zap.Logger) Logger

NewLogger creates a new Logger with given zap logger

func WithName

func WithName(s string) Logger

WithName adds a new path segment to the logger's name.

func WithValues

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

WithValues creates a child logger and adds zap fileds to it

type Options

type Options struct {
	OutputPaths       []string `json:"output-paths" mapstructure:"output-paths"`
	ErrorOutputPaths  []string `json:"error-output-paths" mapstructure:"error-output-paths"`
	Level             string   `json:"level" mapstructure:"level"`                   // log-level
	Format            string   `json:"format" mapstructure:"format"`                 // log file output format, JSON or Console(txt)
	DisableCaller     bool     `json:"disable-caller" mapstructure:"disable-caller"` // show name,location and line No. of the funcation called
	DisableStacktrace bool     `json:"disable-stacktrace" mapstructure:"disable-stacktrace"`
	EnableColor       bool     `json:"enable-color" mapstructure:"enable-color"`
	Development       bool     `json:"development" mapstructure:"development"`
	Name              string   `json:"name" mapstructure:"name"`                   // logger name
	CommonFields      []string `json:"common-fields" mapstructure:"common-fields"` // common log fields, eg: requestId, username
}

Options

func NewOptions

func NewOptions() *Options

NewOption creates Options with default params

func (*Options) AddFlags

func (o *Options) AddFlags(fs *pflag.FlagSet)

AddFlags adds flags for log to the specified FlagSet object

func (*Options) String

func (o *Options) String() string

func (*Options) Validate

func (o *Options) Validate() []error

Validate validates the options fields

Jump to

Keyboard shortcuts

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