log

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

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

func Debugf

func Debugf(format string, v ...any)

func Debugw

func Debugw(msg string, keysAndValues ...any)

func Error

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

func Errorf

func Errorf(format string, v ...any)

func Errorw

func Errorw(msg string, keysAndValues ...any)

func Fatal

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

func Fatalf

func Fatalf(format string, v ...any)

func Fatalw

func Fatalw(msg string, keysAndValues ...any)

func Flush

func Flush()

func Info

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

func Infof

func Infof(format string, v ...any)

func Infow

func Infow(msg string, keysAndValues ...any)

func Init

func Init(opts *Options)

Init initializes logger with specified options.

func New

func New(opts *Options) *logger

New create logger by opts which can custmoized by command arguments and config file.

func Panic

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

func Panicf

func Panicf(format string, v ...any)

func Panicw

func Panicw(msg string, keysAndValues ...any)

func Warn

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

func Warnf

func Warnf(format string, v ...any)

func Warnw

func Warnw(msg string, keysAndValues ...any)

func WithContext

func WithContext(ctx context.Context) context.Context

Types

type Field

type Field = zapcore.Field

Field is an alias for the field structure in the zap log frame.

type Logger

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

	// Fulsh calls the underlying ZAP Core's Sync method, flushing any buffered log
	// entries. Applications should take care to call Sync before exiting.
	Flush()
	// WithValues adds some key-value pairs of context to a logger.
	WithValues(keysAndValues ...any) Logger
	// WithName adds a new element to the logger's name.
	// Successive calls with WithName continue to append
	// suffixes to the logger's name.
	WithName(name string) Logger
	// WithContext returns a copy of context in which the log value is set.
	WithContext(ctx context.Context) context.Context
}

Logger defines the capabilities that a logger has.

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 returns a new Logger.

func WithName

func WithName(name string) Logger

func WithValues

func WithValues(keysAndValues ...any) Logger

type Options

type Options struct {
	OutputPaths       []string `json:"log-output-paths"       mapstructure:"log-output-paths"`
	ErrorOutputPaths  []string `json:"log-error-output-paths" mapstructure:"log-error-output-paths"`
	Level             string   `json:"log-level"              mapstructure:"log-level"`
	Format            string   `json:"log-format"             mapstructure:"log-format"`
	DisableCaller     bool     `json:"log-disable-caller"     mapstructure:"log-disable-caller"`
	DisableStacktrace bool     `json:"log-disable-stacktrace" mapstructure:"log-disable-stacktrace"`
	Development       bool     `json:"log-development"        mapstructure:"log-development"`
	Name              string   `json:"log-name"               mapstructure:"log-name"`
}

Options contains configuration items related to log.

func NewOptions

func NewOptions() *Options

NewOptions creates an Options object with default parameters.

func (*Options) AddFlags

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

AddFlags adds flags for log to the specified FlagSet object.

Jump to

Keyboard shortcuts

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