log

package
v2.0.0-beta1 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2021 License: MIT Imports: 8 Imported by: 1,713

README

Log

Usage

Structured logging
logger := log.NewLogger(os.Stdout)
logger = With(logger, "key", "value")

log := log.NewHelper("github.com/project/foo", logger)
// Levels
log.Info("hello")
log.Infof("hello %s", "kratos")
log.Infow("key", "value")

Documentation

Index

Constants

View Source
const LevelKey = "level"

LevelKey is logger level key.

Variables

This section is empty.

Functions

func Value

func Value(v interface{}) interface{}

Value return the function value.

Types

type Helper

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

Helper is a logger helper.

func NewHelper

func NewHelper(name string, logger Logger) *Helper

NewHelper new a logger helper.

func (*Helper) Debug

func (h *Helper) Debug(a ...interface{})

Debug logs a message at debug level.

func (*Helper) Debugf

func (h *Helper) Debugf(format string, a ...interface{})

Debugf logs a message at debug level.

func (*Helper) Debugw

func (h *Helper) Debugw(pairs ...interface{})

Debugw logs a message at debug level.

func (*Helper) Error

func (h *Helper) Error(a ...interface{})

Error logs a message at error level.

func (*Helper) Errorf

func (h *Helper) Errorf(format string, a ...interface{})

Errorf logs a message at error level.

func (*Helper) Errorw

func (h *Helper) Errorw(pairs ...interface{})

Errorw logs a message at error level.

func (*Helper) Info

func (h *Helper) Info(a ...interface{})

Info logs a message at info level.

func (*Helper) Infof

func (h *Helper) Infof(format string, a ...interface{})

Infof logs a message at info level.

func (*Helper) Infow

func (h *Helper) Infow(pairs ...interface{})

Infow logs a message at info level.

func (*Helper) Warn

func (h *Helper) Warn(a ...interface{})

Warn logs a message at warn level.

func (*Helper) Warnf

func (h *Helper) Warnf(format string, a ...interface{})

Warnf logs a message at warnf level.

func (*Helper) Warnw

func (h *Helper) Warnw(pairs ...interface{})

Warnw logs a message at warnf level.

type Level

type Level int8

Level is a logger level.

const (
	// LevelDebug is logger debug level.
	LevelDebug Level = iota
	// LevelInfo is logger info level.
	LevelInfo
	// LevelWarn is logger warn level.
	LevelWarn
	// LevelError is logger error level.
	LevelError
)

func (Level) String

func (l Level) String() string

type Logger

type Logger interface {
	Print(pairs ...interface{})
}

Logger is a logger interface.

var (
	// DefaultLogger is default logger.
	DefaultLogger Logger = NewStdLogger(log.Writer())
)

func Debug added in v2.1.5

func Debug(log Logger) Logger

Debug returns a debug logger.

func Error added in v2.1.5

func Error(log Logger) Logger

Error returns a error logger.

func Info added in v2.1.5

func Info(log Logger) Logger

Info returns a info logger.

func NewStdLogger

func NewStdLogger(w io.Writer) Logger

NewStdLogger new a std logger with options.

func Warn added in v2.1.5

func Warn(log Logger) Logger

Warn return a warn logger.

func With

func With(l Logger, a ...interface{}) Logger

With with logger fields.

func Wrap

func Wrap(logs ...Logger) Logger

Wrap wraps multi logger.

type Valuer

type Valuer func() interface{}

Valuer is returns a log value.

func Caller

func Caller(depth int) Valuer

Caller returns returns a Valuer that returns a pkg/file:line description of the caller.

type Verbose

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

Verbose is a verbose type that implements Logger Print.

func NewVerbose

func NewVerbose(log Logger, level Level) Verbose

NewVerbose new a verbose with level.

func (Verbose) Enabled

func (v Verbose) Enabled(level Level) bool

Enabled will return true if this log level is enabled, guarded by the value of v.

func (Verbose) Print

func (v Verbose) Print(a ...interface{})

Print is equivalent to the Print function, guarded by the value of v.

func (Verbose) V

func (v Verbose) V(level Level) Verbose

V reports whether verbosity at the call site is at least the requested level.

Jump to

Keyboard shortcuts

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