slogger

package
v0.0.0-...-e264994 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CapLogCache

func CapLogCache(size int)

func FormatLog

func FormatLog(log *Log) string

func TurboLevelFilter

func TurboLevelFilter(threshold Level) func(Level, string, ...interface{}) bool

Types

type Appender

type Appender interface {
	Append(log *Log) error
}

type FileAppender

type FileAppender struct {
	WriteStringer
}

WriteStringer is implemented by *os.File.

func DevNullAppender

func DevNullAppender() (*FileAppender, error)

func StdErrAppender

func StdErrAppender() *FileAppender

func StdOutAppender

func StdOutAppender() *FileAppender

func (FileAppender) Append

func (self FileAppender) Append(log *Log) error

type Filter

type Filter func(log *Log) bool

Return true if the log should be passed to the underlying `Appender`

type FilterAppender

type FilterAppender struct {
	Appender Appender
	Filter   Filter
}

func LevelFilter

func LevelFilter(threshold Level, appender Appender) *FilterAppender

func (*FilterAppender) Append

func (self *FilterAppender) Append(log *Log) error

type Level

type Level uint8
const (
	DEBUG Level = iota
	INFO
	WARN
	ERROR
	OFF
)

The level is in an order such that the expressions `level < WARN`, `level >= INFO` have intuitive meaning.

func (Level) Type

func (self Level) Type() string

type Log

type Log struct {
	Prefix    string
	Level     Level
	Filename  string
	Line      int
	Timestamp time.Time
	// contains filtered or unexported fields
}

func (*Log) Message

func (self *Log) Message() string

type LogCache

type LogCache struct {
	// A `LogCache` might be accessed concurrently throughout the
	// program. Therefore, the code calling `Log` acquires a mutex for
	// writing to (and potentially reading from) the
	// ring. Alternatively, if channels are more efficient, the `Log`
	// method can instead pass the *Log through a channel. A goroutine
	// on the other end can be the sole maintainer of the `LogCache`,
	// removing the need for a mutex.
	sync.Mutex
	// contains filtered or unexported fields
}
var Cache LogCache

func (*LogCache) Add

func (self *LogCache) Add(log *Log)

func (*LogCache) Copy

func (self *LogCache) Copy() []*Log

func (*LogCache) Len

func (self *LogCache) Len() int

type Logger

type Logger struct {
	Prefix       string
	Appenders    []Appender
	TurboFilters []TurboFilter
}

func (*Logger) Errorf

func (self *Logger) Errorf(level Level, messageFmt string, args ...interface{}) error

Log and return a formatted error string. Example:

if whatIsExpected != whatIsReturned {
    return slogger.Errorf(slogger.WARN, "Unexpected return value. Expected: %v Received: %v",
        whatIsExpected, whatIsReturned)
}

func (*Logger) Logf

func (self *Logger) Logf(level Level, messageFmt string, args ...interface{}) (*Log, []error)

Log a message and a level to a logger instance. This returns a pointer to a Log and a slice of errors that were gathered from every Appender (nil errors included), or nil and an empty error slice if any turbo filter condition was not satisfied causing an early exit.

func (*Logger) Stackf

func (self *Logger) Stackf(level Level, stackErr error, messageFmt string, args ...interface{}) (*Log, []error)

Stackf is designed to work in tandem with `NewStackError`. This function is similar to `Logf`, but takes a `stackErr` parameter. `stackErr` is expected to be of type StackError, but does not have to be.

type StackError

type StackError struct {
	Message    string
	Stacktrace []string
}

func NewStackError

func NewStackError(messageFmt string, args ...interface{}) *StackError

func (*StackError) Error

func (self *StackError) Error() string

type StringAppender

type StringAppender struct {
	*bytes.Buffer
}

func NewStringAppender

func NewStringAppender(buffer *bytes.Buffer) *StringAppender

func (StringAppender) Append

func (self StringAppender) Append(log *Log) error

type TurboFilter

type TurboFilter func(level Level, messageFmt string, args ...interface{}) bool

enables level-filtering before a Log entry is created, avoiding the runtime.Caller invocation return true if filter evaluation should continue

type WriteStringer

type WriteStringer interface {
	WriteString(str string) (int, error)
}

Jump to

Keyboard shortcuts

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