Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zaptest: Provide verifying logger to notice unexpected logs #520

Open
prashantv opened this issue Oct 30, 2017 · 1 comment
Open

zaptest: Provide verifying logger to notice unexpected logs #520

prashantv opened this issue Oct 30, 2017 · 1 comment

Comments

@prashantv
Copy link
Collaborator

Want something to provide functionality similar to tchannel-go, a logger which will fail when it sees unexpected log messages.

Ideally, we'd avoid requiring a defer by:

  • Create a logger with a set of options for what is allowed ideally using functional options that allow you to do things like IgnoreMessage("message").AnyTimes(), or specify minimum levels etc
  • Store all logs in-memory, until it receives an unexpected log message
  • Once we hit a bad message, fail the test, log all previous messages (probably using t.Log), and then start logging all further messages to the logger.
@WGH-
Copy link

WGH- commented Jan 16, 2023

This doesn't satisfy all the requirements you mentioned, but it's still "a logger which will fail when it sees unexpected log messages" implemented with just a little bit of boilerplate:

core, observedLogs := observer.New(zap.WarnLevel)
defer func() {
	assert.Empty(t, observedLogs.TakeAll())
}()
logger := zap.New(core)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants