logging

package
v0.0.0-...-ed3cc77 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2018 License: MIT Imports: 14 Imported by: 0

README

Logging based on github.com/go-uber/zap

GoDoc

Documentation

Index

Constants

View Source
const (
	// RootLoggerName is the name of the root logger
	RootLoggerName = Name("")
	// RootLoggerAlias is an alias of the root logger
	RootLoggerAlias = "all"
)
View Source
const (
	DebugLevel = zap.DebugLevel
	InfoLevel  = zap.InfoLevel
	WarnLevel  = zap.WarnLevel
	ErrorLevel = zap.ErrorLevel
	PanicLevel = zap.PanicLevel
	FatalLevel = zap.FatalLevel
)

===========================================================================

Variables

This section is empty.

Functions

func AddLogger

func AddLogger(logger Logger) func(http.Handler) http.Handler

AddLogger returns an HTTP middleware that injects the given logger to the request context

func CatchPanic

func CatchPanic(f func()) (err error)

CatchPanic calls a function, returning any panic as error

func RecoverError

func RecoverError() error

RecoverError recovers from a panic and returns an error in that case

func WithLogger

func WithLogger(ctx context.Context, l Logger) context.Context

WithLogger creates a Context with the Logger

Types

type Config

type Config struct {
	Level LoggerLevels
	Quiet bool
	Debug bool
}

Config holds the logging configuration and is used the build the Factory.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a default configuration

func (*Config) Build

func (c *Config) Build() *Factory

Build creates the Logger Factory

type Factory

type Factory struct {
	Config
	// contains filtered or unexported fields
}

Factory is used to build Loggers.

func (*Factory) Get

func (f *Factory) Get(s string) Logger

Get returns a Logger for the given name.

type Logger

type Logger interface {
	DPanic(...interface{})
	DPanicf(string, ...interface{})
	DPanicw(string, ...interface{})

	Debug(...interface{})
	Debugf(string, ...interface{})
	Debugw(string, ...interface{})

	Error(...interface{})
	Errorf(string, ...interface{})
	Errorw(string, ...interface{})

	Fatal(...interface{})
	Fatalf(string, ...interface{})
	Fatalw(string, ...interface{})

	Info(...interface{})
	Infof(string, ...interface{})
	Infow(string, ...interface{})

	Panic(...interface{})
	Panicf(string, ...interface{})
	Panicw(string, ...interface{})

	Warn(...interface{})
	Warnf(string, ...interface{})
	Warnw(string, ...interface{})

	Named(string) Logger
	With(...interface{}) Logger
	Sync() error

	Writer() io.WriteCloser
	StdLoggerAt(zapcore.Level) (*log.Logger, error)
}

Logger is a logger object

func FromContext

func FromContext(ctx context.Context, def Logger) Logger

FromContext gets the Logger from the Context

func MustFromContext

func MustFromContext(ctx context.Context) Logger

FromContext gets the Logger from the Context

func NewTesting

func NewTesting(t *testing.T) Logger

NewTesting creates a logger that forwards everything to the testing log.

type LoggerLevels

type LoggerLevels map[Name]zapcore.Level

LoggerLevels is a map of Levels for Logger Names

func (LoggerLevels) Get

func (l LoggerLevels) Get() interface{}

Get implements flags.Getter

func (LoggerLevels) Resolve

func (l LoggerLevels) Resolve(name Name) zapcore.Level

Resolve returns the Level to use for the Named Logger.

func (LoggerLevels) Set

func (l LoggerLevels) Set(value string) (err error)

Set implements flags.Value. It parses a comma-separater strings of name:level couples.

func (LoggerLevels) String

func (l LoggerLevels) String() string

Get implements fmt.Stringer

type Name

type Name string

Name is a clean, full Logger name

func Clean

func Clean(name string) Name

Clean creates a Logger Name from a string

func (Name) Child

func (n Name) Child(s string) Name

Child returns the full Name of a child Logger.

func (Name) Parent

func (n Name) Parent() Name

Parent returns the full Name of the parent Logger.

func (Name) String

func (n Name) String() string

String implements fmt.Stringer

Jump to

Keyboard shortcuts

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