common

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2020 License: MPL-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorInheritf

func ErrorInheritf(err error, msg string, f ...interface{}) error

ErrorInheritf creates a new error. It tries to set the permanent flag based on the provided error.

func ErrorPermf

func ErrorPermf(msg string, f ...interface{}) error

ErrorPermf returns permanent error

func ErrorTempf

func ErrorTempf(msg string, f ...interface{}) error

ErrorTempf returns temporary error

func IsErrorTemporary

func IsErrorTemporary(err error) bool

IsErrorTemporary tries to guess if an error is temporary or fatal If unsure - report as temporary

func LoggerHeader

func LoggerHeader(l Source) string

LoggerHeader returns a log header for a particular source

func RetryForever

func RetryForever(ctx context.Context, p RetryParams) (err error)

RetryForever executes the provided function F() from RetryParams until succeeded It logs to logger, increments error counter and reports to prometheus (if any of these were provided)

Types

type Common

type Common interface {
	Name() string
	Type() string

	Stats() string
	Status() error
	Close() error

	SetDebug(bool)
	SetVerbose(bool)
}

Common is a common set of functions embedded by sinks & sources

type Error

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

Error is a common error type with permanent flag

func (Error) Error

func (e Error) Error() string

func (Error) Temporary

func (e Error) Temporary() bool

Temporary returns false if the error is permanent

type Logger

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

Logger is embedded by sinks & sources structs

func LoggerCreate

func LoggerCreate(l Source, v *viper.Viper) *Logger

LoggerCreate creates a logger

func (*Logger) Debugf

func (l *Logger) Debugf(m string, f ...interface{})

Debugf logs if debug

func (*Logger) Errorf

func (l *Logger) Errorf(m string, f ...interface{})

Errorf logs error (generic currently)

func (*Logger) LogDebugEv

func (l *Logger) LogDebugEv(uuid string, m string, f ...interface{})

LogDebugEv logs event if debug

func (*Logger) LogEv

func (l *Logger) LogEv(uuid string, m string, f ...interface{})

LogEv logs event

func (*Logger) LogVerboseEv

func (l *Logger) LogVerboseEv(uuid string, m string, f ...interface{})

LogVerboseEv logs event if verbose

func (*Logger) Logf

func (l *Logger) Logf(m string, f ...interface{})

Logf logs!

func (*Logger) SetDebug

func (l *Logger) SetDebug(d bool)

SetDebug toggles the debug mode

func (*Logger) SetVerbose

func (l *Logger) SetVerbose(d bool)

SetVerbose toggles the verbose mode

type RetryParams

type RetryParams struct {
	F        func() error
	Interval time.Duration
	Logger   *Logger

	// errorMsg should have %d and %s placeholders for retry count and error
	ErrorMsg            string
	ErrorCounter        *uint64
	PromErrorCounter    prometheus.Counter
	RetryPermanentError bool
}

RetryParams are params for RetryForever

type Source

type Source interface {
	Name() string
	Type() string
}

Source is an interface implementing a source for logs

Jump to

Keyboard shortcuts

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