log

package
v2.0.0-alpha1 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2021 License: MIT Imports: 5 Imported by: 1,713

README

Log

Usage

Structured logging
logger := stdlog.NewLogger(stdlog.Writer(os.Stdout))
log := log.NewHelper("module_name", logger)
// Levels
log.Info("some log")
log.Infof("format %s", "some log")
log.Infow("field_name", "some log")

Documentation

Index

Constants

View Source
const (
	// LevelKey is logger level key.
	LevelKey = "level"
)

Variables

This section is empty.

Functions

This section is empty.

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(kvpair ...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(kvpair ...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(kvpair ...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(kvpair ...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) Enabled

func (l Level) Enabled(lv Level) bool

Enabled compare whether the logging level is enabled.

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()
)

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() 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(log Logger, pairs ...interface{}) Logger

With with logger kv pairs.

Jump to

Keyboard shortcuts

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