testlogger

package
v3.1.0 Latest Latest
Warning

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

Go to latest
Published: May 19, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TestLogEvent

type TestLogEvent struct {
	Method, Key string
	Val         interface{}
	Next        *TestLogEvent
	// contains filtered or unexported fields
}

TestLogEvent describes one item in a linked list that holds a single log message.

func (*TestLogEvent) AnErr

func (ev *TestLogEvent) AnErr(key string, val error) ech0.ZeroEvent

func (*TestLogEvent) Bool

func (ev *TestLogEvent) Bool(key string, val bool) ech0.ZeroEvent

func (*TestLogEvent) Bools added in v3.1.0

func (ev *TestLogEvent) Bools(key string, val []bool) ech0.ZeroEvent

func (*TestLogEvent) Bytes

func (ev *TestLogEvent) Bytes(key string, val []byte) ech0.ZeroEvent

func (*TestLogEvent) Dict added in v3.1.0

func (ev *TestLogEvent) Dict(key string, dict ech0.ZeroEvent) ech0.ZeroEvent

func (*TestLogEvent) Dur

func (ev *TestLogEvent) Dur(key string, val time.Duration) ech0.ZeroEvent

func (*TestLogEvent) Err

func (ev *TestLogEvent) Err(err error) ech0.ZeroEvent

func (*TestLogEvent) FindByKey

func (ev *TestLogEvent) FindByKey(key string) *TestLogEvent

FindByKey searches through the linked list of TestLogEvents to find the (first) one with a given key, or the end of the list (nil). Use with Value.

func (*TestLogEvent) Hex

func (ev *TestLogEvent) Hex(key string, val []byte) ech0.ZeroEvent

func (*TestLogEvent) Int

func (ev *TestLogEvent) Int(key string, val int) ech0.ZeroEvent

func (*TestLogEvent) Int64

func (ev *TestLogEvent) Int64(key string, val int64) ech0.ZeroEvent

func (*TestLogEvent) Interface

func (ev *TestLogEvent) Interface(key string, val interface{}) ech0.ZeroEvent

func (*TestLogEvent) Ints

func (ev *TestLogEvent) Ints(key string, val []int) ech0.ZeroEvent

func (*TestLogEvent) Msg

func (ev *TestLogEvent) Msg(s string)

func (*TestLogEvent) Msgf

func (ev *TestLogEvent) Msgf(format string, v ...interface{})

func (*TestLogEvent) Send

func (ev *TestLogEvent) Send()

func (*TestLogEvent) Str

func (ev *TestLogEvent) Str(key, val string) ech0.ZeroEvent

func (*TestLogEvent) String

func (ev *TestLogEvent) String() string

func (*TestLogEvent) Stringer

func (ev *TestLogEvent) Stringer(key string, val fmt.Stringer) ech0.ZeroEvent

func (*TestLogEvent) Strs

func (ev *TestLogEvent) Strs(key string, val []string) ech0.ZeroEvent

func (*TestLogEvent) Time

func (ev *TestLogEvent) Time(key string, val time.Time) ech0.ZeroEvent

func (*TestLogEvent) Timestamp added in v3.1.0

func (ev *TestLogEvent) Timestamp() ech0.ZeroEvent

func (*TestLogEvent) Uint

func (ev *TestLogEvent) Uint(key string, val uint) ech0.ZeroEvent

func (*TestLogEvent) Uint64

func (ev *TestLogEvent) Uint64(key string, val uint64) ech0.ZeroEvent

func (*TestLogEvent) Uints

func (ev *TestLogEvent) Uints(key string, val []uint) ech0.ZeroEvent

func (*TestLogEvent) Value

func (ev *TestLogEvent) Value() interface{}

Value returns the value of one list item. The item may be nil, in which case Value returns nil.

type TestLogEventList

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

TestLogEventList contains a slice of type *TestLogEvent. It encapsulates the slice and provides methods to access or mutate it.

List values follow a similar pattern to Scala Lists and LinearSeqs in particular. For comparison with Scala, see e.g. http://www.scala-lang.org/api/2.11.7/#scala.collection.LinearSeq

func BuildTestLogEventListFromChan

func BuildTestLogEventListFromChan(source <-chan *TestLogEvent) *TestLogEventList

BuildTestLogEventListFromChan constructs a new TestLogEventList from a channel that supplies a sequence of values until it is closed. The function doesn't return until then.

func ConvertTestLogEventList

func ConvertTestLogEventList(values ...interface{}) (*TestLogEventList, bool)

ConvertTestLogEventList constructs a new list containing the supplied values, if any. The returned boolean will be false if any of the values could not be converted correctly. The returned list will contain all the values that were correctly converted.

func MakeTestLogEventList

func MakeTestLogEventList(length, capacity int) *TestLogEventList

MakeTestLogEventList makes an empty list with both length and capacity initialised.

func NewTestLogEventList

func NewTestLogEventList(values ...*TestLogEvent) *TestLogEventList

NewTestLogEventList constructs a new list containing the supplied values, if any.

func (*TestLogEventList) Add

func (list *TestLogEventList) Add(more ...*TestLogEvent)

Add adds items to the current list. This is a synonym for Append.

func (*TestLogEventList) Append

func (list *TestLogEventList) Append(more ...*TestLogEvent) *TestLogEventList

Append adds items to the current list. If the list is nil, a new list is allocated and returned. Otherwise the modified list is returned.

func (*TestLogEventList) Clear

func (list *TestLogEventList) Clear()

Clear the entire collection.

func (*TestLogEventList) Clone

func (list *TestLogEventList) Clone() *TestLogEventList

Clone returns a shallow copy of the list. It does not clone the underlying elements.

func (*TestLogEventList) CountBy

func (list *TestLogEventList) CountBy(p func(*TestLogEvent) bool) (result int)

CountBy gives the number elements of TestLogEventList that return true for the predicate p.

func (*TestLogEventList) DistinctBy

func (list *TestLogEventList) DistinctBy(equal func(*TestLogEvent, *TestLogEvent) bool) *TestLogEventList

DistinctBy returns a new TestLogEventList whose elements are unique, where equality is defined by the equal function.

func (*TestLogEventList) DoDeleteAt

func (list *TestLogEventList) DoDeleteAt(index, n int) *TestLogEventList

DoDeleteAt modifies a TestLogEventList by deleting n elements from a given index.

The list is modified and the modified list is returned. Panics if the index is out of range or n is large enough to take the index out of range.

func (*TestLogEventList) DoDeleteFirst

func (list *TestLogEventList) DoDeleteFirst(n int) *TestLogEventList

DoDeleteFirst modifies a TestLogEventList by deleting n elements from the start of the list.

If the list is nil, a new list is allocated and returned. Otherwise the modified list is returned. Panics if n is large enough to take the index out of range.

func (*TestLogEventList) DoDeleteLast

func (list *TestLogEventList) DoDeleteLast(n int) *TestLogEventList

DoDeleteLast modifies a TestLogEventList by deleting n elements from the end of the list.

The list is modified and the modified list is returned. Panics if n is large enough to take the index out of range.

func (*TestLogEventList) DoInsertAt

func (list *TestLogEventList) DoInsertAt(index int, more ...*TestLogEvent) *TestLogEventList

DoInsertAt modifies a TestLogEventList by inserting elements at a given index. This is a generalised version of Append.

If the list is nil, a new list is allocated and returned. Otherwise the modified list is returned. Panics if the index is out of range.

func (*TestLogEventList) DoKeepWhere

func (list *TestLogEventList) DoKeepWhere(p func(*TestLogEvent) bool) *TestLogEventList

DoKeepWhere modifies a TestLogEventList by retaining only those elements that match the predicate p. This is very similar to Filter but alters the list in place.

The list is modified and the modified list is returned.

func (*TestLogEventList) DoReverse

func (list *TestLogEventList) DoReverse() *TestLogEventList

DoReverse alters a TestLogEventList with all elements in the reverse order. Unlike Reverse, it does not allocate new memory.

The list is modified and the modified list is returned.

func (*TestLogEventList) DoShuffle

func (list *TestLogEventList) DoShuffle() *TestLogEventList

DoShuffle returns a shuffled TestLogEventList, using a version of the Fisher-Yates shuffle.

The list is modified and the modified list is returned.

func (*TestLogEventList) Drop

func (list *TestLogEventList) Drop(n int) *TestLogEventList

Drop returns a slice of TestLogEventList without the leading n elements of the source list. If n is greater than or equal to the size of the list, an empty list is returned.

The original list is not modified.

func (*TestLogEventList) DropLast

func (list *TestLogEventList) DropLast(n int) *TestLogEventList

DropLast returns a slice of TestLogEventList without the trailing n elements of the source list. If n is greater than or equal to the size of the list, an empty list is returned.

The original list is not modified.

func (*TestLogEventList) DropWhile

func (list *TestLogEventList) DropWhile(p func(*TestLogEvent) bool) *TestLogEventList

DropWhile returns a new TestLogEventList containing the trailing elements of the source list. Whilst the predicate p returns true, elements are excluded from the result. Once predicate p returns false, all remaining elements are added.

The original list is not modified.

func (*TestLogEventList) Exists

func (list *TestLogEventList) Exists(p func(*TestLogEvent) bool) bool

Exists verifies that one or more elements of TestLogEventList return true for the predicate p.

func (*TestLogEventList) Filter

func (list *TestLogEventList) Filter(p func(*TestLogEvent) bool) *TestLogEventList

Filter returns a new TestLogEventList whose elements return true for predicate p.

The original list is not modified. See also DoKeepWhere (which does modify the original list).

func (*TestLogEventList) Find

func (list *TestLogEventList) Find(p func(*TestLogEvent) bool) (*TestLogEvent, bool)

Find returns the first TestLogEvent that returns true for predicate p. False is returned if none match.

func (*TestLogEventList) First

func (list *TestLogEventList) First() *TestLogEvent

First returns the first event. This returns nil if the list is empty.

func (*TestLogEventList) FlatMap

func (list *TestLogEventList) FlatMap(f func(*TestLogEvent) []*TestLogEvent) *TestLogEventList

FlatMap returns a new TestLogEventList by transforming every element with function f that returns zero or more items in a slice. The resulting list may have a different size to the original list. The original list is not modified.

This is a domain-to-range mapping function. For bespoke transformations to other types, copy and modify this method appropriately.

func (*TestLogEventList) Fold

Fold aggregates all the values in the list using a supplied function, starting from some initial value.

func (*TestLogEventList) Forall

func (list *TestLogEventList) Forall(p func(*TestLogEvent) bool) bool

Forall verifies that all elements of TestLogEventList return true for the predicate p.

func (*TestLogEventList) Foreach

func (list *TestLogEventList) Foreach(f func(*TestLogEvent))

Foreach iterates over TestLogEventList and executes function f against each element. The function can safely alter the values via side-effects.

func (*TestLogEventList) Get

func (list *TestLogEventList) Get(i int) *TestLogEvent

Get gets the specified element in the list. Panics if the index is out of range or the list is nil.

func (*TestLogEventList) Head

func (list *TestLogEventList) Head() *TestLogEvent

Head gets the first element in the list. Head plus Tail include the whole list. Head is the opposite of Last. Panics if list is empty or nil.

func (*TestLogEventList) HeadOption

func (list *TestLogEventList) HeadOption() (*TestLogEvent, bool)

HeadOption gets the first element in the list, if possible. Otherwise returns nil.

func (*TestLogEventList) IndexWhere

func (list *TestLogEventList) IndexWhere(p func(*TestLogEvent) bool) int

IndexWhere finds the index of the first element satisfying predicate p. If none exists, -1 is returned.

func (*TestLogEventList) IndexWhere2

func (list *TestLogEventList) IndexWhere2(p func(*TestLogEvent) bool, from int) int

IndexWhere2 finds the index of the first element satisfying predicate p at or after some start index. If none exists, -1 is returned.

func (*TestLogEventList) Init

func (list *TestLogEventList) Init() *TestLogEventList

Init gets everything except the last. Init plus Last include the whole list. Init is the opposite of Tail. Panics if list is empty or nil.

func (*TestLogEventList) IsEmpty

func (list *TestLogEventList) IsEmpty() bool

IsEmpty tests whether TestLogEventList is empty.

func (*TestLogEventList) IsSequence

func (list *TestLogEventList) IsSequence() bool

IsSequence returns true for lists and queues.

func (*TestLogEventList) IsSet

func (list *TestLogEventList) IsSet() bool

IsSet returns false for lists or queues.

func (*TestLogEventList) Last

func (list *TestLogEventList) Last() *TestLogEvent

Last returns the last event. This returns nil if the list is empty.

func (*TestLogEventList) LastIndexWhere

func (list *TestLogEventList) LastIndexWhere(p func(*TestLogEvent) bool) int

LastIndexWhere finds the index of the last element satisfying predicate p. If none exists, -1 is returned.

func (*TestLogEventList) LastIndexWhere2

func (list *TestLogEventList) LastIndexWhere2(p func(*TestLogEvent) bool, before int) int

LastIndexWhere2 finds the index of the last element satisfying predicate p at or before some start index. If none exists, -1 is returned.

func (*TestLogEventList) LastOption

func (list *TestLogEventList) LastOption() (*TestLogEvent, bool)

LastOption gets the last element in the list, if possible. Otherwise returns nil.

func (*TestLogEventList) Len

func (list *TestLogEventList) Len() int

Len returns the number of items in the list - an alias of Size(). This is one of the three methods in the standard sort.Interface.

func (*TestLogEventList) Map

Map returns a new TestLogEventList by transforming every element with function f. The resulting list is the same size as the original list. The original list is not modified.

This is a domain-to-range mapping function. For bespoke transformations to other types, copy and modify this method appropriately.

func (*TestLogEventList) MaxBy

func (list *TestLogEventList) MaxBy(less func(*TestLogEvent, *TestLogEvent) bool) *TestLogEvent

MaxBy returns an element of TestLogEventList containing the maximum value, when compared to other elements using a passed func defining ‘less’. In the case of multiple items being equally maximal, the first such element is returned. Panics if there are no elements.

func (*TestLogEventList) MinBy

func (list *TestLogEventList) MinBy(less func(*TestLogEvent, *TestLogEvent) bool) *TestLogEvent

MinBy returns an element of TestLogEventList containing the minimum value, when compared to other elements using a passed func defining ‘less’. In the case of multiple items being equally minimal, the first such element is returned. Panics if there are no elements.

func (*TestLogEventList) NonEmpty

func (list *TestLogEventList) NonEmpty() bool

NonEmpty tests whether TestLogEventList is empty.

func (*TestLogEventList) Partition

func (list *TestLogEventList) Partition(p func(*TestLogEvent) bool) (*TestLogEventList, *TestLogEventList)

Partition returns two new TestLogEventLists whose elements return true or false for the predicate, p. The first result consists of all elements that satisfy the predicate and the second result consists of all elements that don't. The relative order of the elements in the results is the same as in the original list.

The original list is not modified

func (*TestLogEventList) Reverse

func (list *TestLogEventList) Reverse() *TestLogEventList

Reverse returns a copy of TestLogEventList with all elements in the reverse order.

The original list is not modified.

func (*TestLogEventList) Send

func (list *TestLogEventList) Send() <-chan *TestLogEvent

Send returns a channel that will send all the elements in order. A goroutine is created to send the elements; this only terminates when all the elements have been consumed. The channel will be closed when all the elements have been sent.

func (*TestLogEventList) Shuffle

func (list *TestLogEventList) Shuffle() *TestLogEventList

Shuffle returns a shuffled copy of TestLogEventList, using a version of the Fisher-Yates shuffle.

The original list is not modified.

func (*TestLogEventList) Size

func (list *TestLogEventList) Size() int

Size returns the number of items in the list - an alias of Len().

func (*TestLogEventList) SortBy

func (list *TestLogEventList) SortBy(less func(i, j *TestLogEvent) bool) *TestLogEventList

SortBy alters the list so that the elements are sorted by a specified ordering. Sorting happens in-place; the modified list is returned.

func (*TestLogEventList) StableSortBy

func (list *TestLogEventList) StableSortBy(less func(i, j *TestLogEvent) bool) *TestLogEventList

StableSortBy alters the list so that the elements are sorted by a specified ordering. Sorting happens in-place; the modified list is returned. The algorithm keeps the original order of equal elements.

func (*TestLogEventList) Swap

func (list *TestLogEventList) Swap(i, j int)

Swap exchanges two elements, which is necessary during sorting etc. This is one of the three methods in the standard sort.Interface.

func (*TestLogEventList) Tail

func (list *TestLogEventList) Tail() *TestLogEventList

Tail gets everything except the head. Head plus Tail include the whole list. Tail is the opposite of Init. Panics if list is empty or nil.

func (*TestLogEventList) Take

func (list *TestLogEventList) Take(n int) *TestLogEventList

Take returns a slice of TestLogEventList containing the leading n elements of the source list. If n is greater than or equal to the size of the list, the whole original list is returned.

func (*TestLogEventList) TakeLast

func (list *TestLogEventList) TakeLast(n int) *TestLogEventList

TakeLast returns a slice of TestLogEventList containing the trailing n elements of the source list. If n is greater than or equal to the size of the list, the whole original list is returned.

The original list is not modified.

func (*TestLogEventList) TakeWhile

func (list *TestLogEventList) TakeWhile(p func(*TestLogEvent) bool) *TestLogEventList

TakeWhile returns a new TestLogEventList containing the leading elements of the source list. Whilst the predicate p returns true, elements are added to the result. Once predicate p returns false, all remaining elements are excluded.

The original list is not modified.

func (*TestLogEventList) ToInterfaceSlice

func (list *TestLogEventList) ToInterfaceSlice() []interface{}

ToInterfaceSlice returns the elements of the current list as a slice of arbitrary type.

func (*TestLogEventList) ToList

func (list *TestLogEventList) ToList() *TestLogEventList

ToList returns the elements of the list as a list, which is an identity operation in this case.

func (*TestLogEventList) ToSlice

func (list *TestLogEventList) ToSlice() []*TestLogEvent

ToSlice returns the elements of the current list as a slice.

type TestLogger

type TestLogger struct {
	Infos  *TestLogEventList
	Warns  *TestLogEventList
	Errors *TestLogEventList
	Panics *TestLogEventList
	// contains filtered or unexported fields
}

TestLogger captures log messages, organised by level: Infos, Warns, Errors and Panics. It deliberately ignores Debug level messages.

Note that Fatal will call os.Exit so cannot usefully be tested.

func New

func New(realLogger ech0.Zero) *TestLogger

func NewWithConsoleLogger

func NewWithConsoleLogger() *TestLogger

NewWithConsoleLogger creates a new test logger with a wrapped console logger.

func (*TestLogger) Debug

func (l *TestLogger) Debug() ech0.ZeroEvent

func (*TestLogger) Err

func (l *TestLogger) Err(err error) ech0.ZeroEvent

func (*TestLogger) Error

func (l *TestLogger) Error() ech0.ZeroEvent

func (*TestLogger) Fatal

func (l *TestLogger) Fatal() ech0.ZeroEvent

Fatal starts a new message with fatal level. The os.Exit(1) function is called by the Msg method, which terminates the program immediately. Therefore, this should be avoided during testing.

func (*TestLogger) Info

func (l *TestLogger) Info() ech0.ZeroEvent

func (*TestLogger) Int

func (l *TestLogger) Int(key string, val int) ech0.Zero

func (*TestLogger) LastError

func (l *TestLogger) LastError() *TestLogEvent

func (*TestLogger) LastInfo

func (l *TestLogger) LastInfo() *TestLogEvent

func (*TestLogger) LastWarn

func (l *TestLogger) LastWarn() *TestLogEvent

func (*TestLogger) Level

func (l *TestLogger) Level(lvl zerolog.Level) ech0.Zero

func (*TestLogger) Log

func (l *TestLogger) Log() ech0.ZeroEvent

func (*TestLogger) Output

func (l *TestLogger) Output(w io.Writer) ech0.Zero

func (*TestLogger) Panic

func (l *TestLogger) Panic() ech0.ZeroEvent

func (*TestLogger) RawJSON

func (l *TestLogger) RawJSON(key string, val []byte) ech0.Zero

func (*TestLogger) Reset

func (l *TestLogger) Reset()

func (*TestLogger) Str

func (l *TestLogger) Str(key, val string) ech0.Zero

func (*TestLogger) Timestamp

func (l *TestLogger) Timestamp() ech0.Zero

func (*TestLogger) Warn

func (l *TestLogger) Warn() ech0.ZeroEvent

func (*TestLogger) WithLevel

func (l *TestLogger) WithLevel(level zerolog.Level) ech0.ZeroEvent

Jump to

Keyboard shortcuts

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