Documentation ¶
Overview ¶
Package glager provides Gomega matchers to verify lager logging.
See https://github.com/onsi/gomega and https://code.cloudfoundry.org/lager for more information.
Index ¶
- Variables
- func Action(action string) option
- func ContainSequence(expectedSequence ...logEntry) types.GomegaMatcher
- func Data(kv ...interface{}) option
- func Debug(options ...option) logEntry
- func Entry(logLevel lager.LogLevel, options ...option) logEntry
- func Error(err error, options ...option) logEntry
- func Fatal(err error, options ...option) logEntry
- func HaveLogged(expectedSequence ...logEntry) types.GomegaMatcher
- func Info(options ...option) logEntry
- func Message(msg string) option
- func Source(src string) option
- type ContentsProvider
- type TestLogger
Constants ¶
This section is empty.
Variables ¶
var AnyErr error = nil
AnyErr can be used to check of arbitrary errors when matching Error entries.
Functions ¶
func Action ¶
func Action(action string) option
Action is an alias for Message, lager uses the term action is used alternatively to message.
func ContainSequence ¶
func ContainSequence(expectedSequence ...logEntry) types.GomegaMatcher
ContainSequence checks if the specified entries appear inside the log in the right order. The entries do not have to be contiguous inide the log, all that matters is their respective order.
Log entries passed to this mtcher do not have to be complete, i.e. you do not have to specify all available properties but only the ones you are actually interested in. Unspecified properties are being ignored when matching the entries, i.e they can have arbitrary values.
This matcher works best when used with a Buffer.
Example:
// instantiate regular lager logger and register buffer as sink log := gbytes.NewBuffer() logger := lager.NewLogger("test") logger.RegisterSink(lager.NewWriterSink(log, lager.DEBUG)) // pass it to your code and use it in there to log stuff myFunc(logger) // verify logging inside your test, using the log buffer // in this example we are only interested in the data of the log entries Expect(log).To(ContainSequence( Info( Data("event", "start"), ), Info( Data("event", "done"), ), ))
func Data ¶
func Data(kv ...interface{}) option
Data specifies the data logged by a given log entry. Arguments are specified as an alternating sequence of keys (string) and values (interface{}).
func Debug ¶
func Debug(options ...option) logEntry
Debug returns a log entry of type lager.DEBUG that can be used with the HaveLogged and ContainSequence matchers.
func Entry ¶
Entry returns a log entry for the specified log level that can be used with the HaveLogged and ContainSequence matchers.
func Error ¶
func Error(err error, options ...option) logEntry
Error returns a log entry of type lager.ERROR that can be used with the HaveLogged and ContainSequence matchers.
func Fatal ¶
func Fatal(err error, options ...option) logEntry
Fatal returns a log entry of type lager.FATAL that can be used with the HaveLogged and ContainSequence matchers.
func HaveLogged ¶
func HaveLogged(expectedSequence ...logEntry) types.GomegaMatcher
HaveLogged is an alias for ContainSequence. It checks if the specified entries appear inside the log in the right sequence. The entries do not have to be contiguous in the log, all that matters is the order and the properties of the entries.
Log entries passed to this mtcher do not have to be complete, i.e. you do not have to specify all available properties but only the ones you are actually interested in. Unspecified properties are being ignored when matching the entries, i.e they can have arbitrary values.
This matcher works best when used with a TestLogger.
Example:
// instantiate glager.TestLogger inside your test and logger := NewLogger("test") // pass it to your code and use it in there to log stuff myFunc(logger) // verify logging inside your test, using the logger // in this example we are interested in the log level, the message, and the // data of the log entries Expect(logger).To(HaveLogged( Info( Message("test.myFunc"), Data("event", "start"), ), Info( Message("test.myFunc"), Data("event", "done"), ), ))
func Info ¶
func Info(options ...option) logEntry
Info returns a log entry of type lager.INFO that can be used with the HaveLogged and ContainSequence matchers.
Types ¶
type ContentsProvider ¶
type ContentsProvider interface { // Contents returns a slice of bytes. Contents() []byte }
ContentsProvider implements Contents function.
type TestLogger ¶
TestLogger embedds an actual lager logger and implements gbytes.BufferProvider. This comes in handy when used with the HaveLogged matcher.
func NewLogger ¶
func NewLogger(component string) *TestLogger
NewLogger returns a new TestLogger that can be used with the HaveLogged matcher. The returned logger uses log level lager.DEBUG.
func (*TestLogger) Buffer ¶
func (l *TestLogger) Buffer() *gbytes.Buffer
Buffer implements gbytes.BufferProvider.Buffer.