log

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ServiceKey is zap field key for service.
	ServiceKey = "service"
	// ComponentKey is zap field key for component.
	ComponentKey = "component"
	// ErrorKey is zap field key for error.
	ErrorKey = "error"
)

Variables

View Source
var NewNopLogger = zap.NewNop

NewNopLogger is alias for zap.NewNop.

Functions

func Component

func Component(name string) zap.Field

Component add zap field with component key.

func ErrorMsg

func ErrorMsg(err error) zap.Field

ErrorMsg add zap field with error key.

func Service

func Service(name string) zap.Field

Service add zap field with service key.

func SyncOnClose

func SyncOnClose(g *run.Group, logger *Logger)

SyncOnClose call log.Sync before run group exit.

Types

type Logger

type Logger = zap.Logger

Logger is type alias for zap.Logger.

func DefaultLogger

func DefaultLogger() (*Logger, error)

DefaultLogger create a default logger, if helpful before logger init.

func NewLogger

func NewLogger(o *Option, opts ...zap.Option) (*Logger, error)

NewLogger create a zap logger by option.

type Option

type Option struct {
	// LogLevel is zap logger level.
	LogLevel string
	// LogEncoding is zap LogEncoding.
	LogEncoding string
	// Caller control if add caller to log.
	Caller bool
	// Prod if true use zap production preset.
	Prod bool
	// contains filtered or unexported fields
}

Option is Logger options.

func (*Option) CreateLogger

func (opt *Option) CreateLogger(opts ...zap.Option) (*Logger, error)

CreateLogger create zap logger from self option.

func (*Option) GetLevel

func (opt *Option) GetLevel() zap.AtomicLevel

GetLevel get inner zap AtomicLevel.

func (*Option) Register

func (opt *Option) Register(app *cobra.Command)

Register register flags to cobra global flag set.

Jump to

Keyboard shortcuts

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