errlog

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2019 License: MIT Imports: 3 Imported by: 0

README

go-errlog

GoDoc Build Status codecov Go Report Card GitHub last commit GitHub tag License

Golang library for logging error with logrus more simply

Features

  • rich error object which has context information and messages
  • logger which logs error object more simply

Usage

See examples and GoDoc.

License

MIT

Documentation

Overview

Package errlog is a library for logging error with logrus more easily.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckField added in v0.5.0

func CheckField(err error, key string, f func(v interface{}) bool) bool

CheckField checks the field's value.

func GetField added in v0.5.0

func GetField(err error, key string) (interface{}, bool)

GetField returns the field value. If error is nil or doesn't have the field, nil and false are returned.

func HasField added in v0.5.0

func HasField(err error, key string) bool

HasField returns whether error has the field.

func HasMsg added in v0.5.0

func HasMsg(err error, msg string) bool

HasMsg returns whether error has the message. If err is nil, returns false. If err isn't base, returns err.Error() == msg .

func New

func New(fields logrus.Fields, msg string, msgs ...string) error

New is a shorthand of combination of Wrap and fmt.Errorf .

func Newf

func Newf(fields logrus.Fields, msg string, a ...interface{}) error

Newf is a shorthand of combination of New and fmt.Sprintf .

func Wrap

func Wrap(err error, fields logrus.Fields, msgs ...string) error

Wrap returns an error added fields and msgs. If err is nil, returns nil.

func Wrapf

func Wrapf(err error, fields logrus.Fields, msg string, a ...interface{}) error

Wrapf is a shordhand of combination of Wrap and fmt.Sprintf . If err is nil, returns nil.

Types

type Logger

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

Logger is a logger for error object.

func NewLogger

func NewLogger(logger LogrusLogger) *Logger

NewLogger returns a logger.

func (*Logger) Debug

func (logger *Logger) Debug(err error, msgs ...string)

Debug outputs debug log. If err is nil, do nothing.

func (*Logger) Debugf added in v0.7.0

func (logger *Logger) Debugf(err error, msg string, a ...interface{})

Debugf outputs debug log. If err is nil, do nothing.

func (*Logger) Error

func (logger *Logger) Error(err error, msgs ...string)

Error outputs error log. If err is nil, do nothing.

func (*Logger) Errorf added in v0.7.0

func (logger *Logger) Errorf(err error, msg string, a ...interface{})

Errorf outputs fatal log. If err is nil, do nothing.

func (*Logger) Fatal

func (logger *Logger) Fatal(err error, msgs ...string)

Fatal outputs fatal log. If err is nil, do nothing.

func (*Logger) Fatalf added in v0.7.0

func (logger *Logger) Fatalf(err error, msg string, a ...interface{})

Fatalf outputs fatal log. If err is nil, do nothing.

func (*Logger) Info

func (logger *Logger) Info(err error, msgs ...string)

Info outputs info log. If err is nil, do nothing.

func (*Logger) Infof added in v0.7.0

func (logger *Logger) Infof(err error, msg string, a ...interface{})

Infof outputs info log. If err is nil, do nothing.

func (*Logger) Logger added in v0.9.0

func (logger *Logger) Logger() LogrusLogger

Logger returns a logger.

func (*Logger) Sdebug added in v0.8.0

func (logger *Logger) Sdebug(msgs ...string)

Sdebug outputs debug log.

func (*Logger) Sdebugf added in v0.8.0

func (logger *Logger) Sdebugf(msg string, a ...interface{})

Sdebugf outputs debug log.

func (*Logger) Serror added in v0.8.0

func (logger *Logger) Serror(msgs ...string)

Serror outputs error log.

func (*Logger) Serrorf added in v0.8.0

func (logger *Logger) Serrorf(msg string, a ...interface{})

Serrorf outputs error log.

func (*Logger) Sfatal added in v0.8.0

func (logger *Logger) Sfatal(msgs ...string)

Sfatal outputs fatal log.

func (*Logger) Sfatalf added in v0.8.0

func (logger *Logger) Sfatalf(msg string, a ...interface{})

Sfatalf outputs fatal log.

func (*Logger) Sinfo added in v0.8.0

func (logger *Logger) Sinfo(msgs ...string)

Sinfo outputs info log.

func (*Logger) Sinfof added in v0.8.0

func (logger *Logger) Sinfof(msg string, a ...interface{})

Sinfof outputs info log.

func (*Logger) Swarn added in v0.8.0

func (logger *Logger) Swarn(msgs ...string)

Swarn outputs warn log.

func (*Logger) Swarnf added in v0.8.0

func (logger *Logger) Swarnf(msg string, a ...interface{})

Swarnf outputs warn log.

func (*Logger) Warn

func (logger *Logger) Warn(err error, msgs ...string)

Warn outputs warn log. If err is nil, do nothing.

func (*Logger) Warnf added in v0.7.0

func (logger *Logger) Warnf(err error, msg string, a ...interface{})

Warnf outputs warn log. If err is nil, do nothing.

func (*Logger) WithField

func (logger *Logger) WithField(key string, value interface{}) *Logger

WithField returns a new logger added given fields and messages.

func (*Logger) WithFields

func (logger *Logger) WithFields(fields logrus.Fields) *Logger

WithFields returns a new logger added given fields and messages.

type LogrusLogger

type LogrusLogger interface {
	Debug(args ...interface{})
	Debugf(format string, args ...interface{})
	Error(args ...interface{})
	Errorf(format string, args ...interface{})
	Fatal(args ...interface{})
	Fatalf(format string, args ...interface{})
	Info(args ...interface{})
	Infof(format string, args ...interface{})
	Warn(args ...interface{})
	Warnf(format string, args ...interface{})
	WithField(key string, value interface{}) *logrus.Entry
	WithFields(fields logrus.Fields) *logrus.Entry
}

LogrusLogger is an interface for logrus.Logger and logrus.Entry .

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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