logx

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

type Logger interface {
	Printf(s string, args ...interface{})
	Sub(p string) Logger
}

Logger defines an interface for a single logger method.

func Nop

func Nop() Logger

Nop is a no-op logger.

func Std

func Std(log *log.Logger, levels []string) Logger

Std is a logger that writes to the standard log package.

type LoggerMock

type LoggerMock struct {
	// PrintfFunc mocks the Printf method.
	PrintfFunc func(s string, args ...interface{})

	// SubFunc mocks the Sub method.
	SubFunc func(p string) Logger
	// contains filtered or unexported fields
}

LoggerMock is a mock implementation of Logger.

func TestSomethingThatUsesLogger(t *testing.T) {

	// make and configure a mocked Logger
	mockedLogger := &LoggerMock{
		PrintfFunc: func(s string, args ...interface{})  {
			panic("mock out the Printf method")
		},
		SubFunc: func(p string) Logger {
			panic("mock out the Sub method")
		},
	}

	// use mockedLogger in code that requires Logger
	// and then make assertions.

}

func (*LoggerMock) Printf

func (mock *LoggerMock) Printf(s string, args ...interface{})

Printf calls PrintfFunc.

func (*LoggerMock) PrintfCalls

func (mock *LoggerMock) PrintfCalls() []struct {
	S    string
	Args []interface{}
}

PrintfCalls gets all the calls that were made to Printf. Check the length with:

len(mockedLogger.PrintfCalls())

func (*LoggerMock) Sub

func (mock *LoggerMock) Sub(p string) Logger

Sub calls SubFunc.

func (*LoggerMock) SubCalls

func (mock *LoggerMock) SubCalls() []struct {
	P string
}

SubCalls gets all the calls that were made to Sub. Check the length with:

len(mockedLogger.SubCalls())

Jump to

Keyboard shortcuts

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