Documentation ¶
Overview ¶
Package testlog provides a test logger and helpers to check log output.
Example ¶
package main import ( "testing" "github.com/heroku/x/testing/testlog" ) func main() { var t *testing.T // use t provided by test function logger, hook := testlog.New() // Use the test logger logger.WithField("a", "b").Info("test") hook.CheckAllContained(t, "a=b", "msg=test") hook.CheckNotContained(t, "unexpected") }
Output:
Example (Discard) ¶
package main import ( "github.com/heroku/x/testing/testlog" ) func main() { logger, _ := testlog.New() // Use the test logger logger.WithField("a", "b").Info("test") }
Output:
Index ¶
- type Hook
- func (t *Hook) CheckAllContained(tb testing.TB, strs ...string)
- func (t *Hook) CheckContained(tb testing.TB, strs ...string)
- func (t *Hook) CheckNotContained(tb testing.TB, strs ...string)
- func (t *Hook) Entries() []*logrus.Entry
- func (t *Hook) Fire(e *logrus.Entry) error
- func (t *Hook) LastEntry() (l *logrus.Entry)
- func (t *Hook) Levels() []logrus.Level
- func (t *Hook) Reset()
- func (t *Hook) String() string
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Hook ¶
Hook is a hook designed for dealing with logs in test scenarios.
func New ¶ added in v0.0.21
New sets up a test logger that produces no output. Use the returned hook to observe and make assertions about what was logged.
func NewNullLogger
deprecated
func (*Hook) CheckAllContained ¶
CheckAllContained looks through all the passed strings and verifies that all of them have been logged.
func (*Hook) CheckContained ¶
CheckContained looks through all the passed strings and verifies that at least one of those have been logged.
func (*Hook) CheckNotContained ¶
CheckNotContained looks through all the passed strings and verifies that none of those fragments have been logged.
Click to show internal directories.
Click to hide internal directories.