-
Notifications
You must be signed in to change notification settings - Fork 1
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
Version 2 #5
Conversation
This also reverts the potential to pass in an existing logger, as it's currently impossible to manipulate the encoder of an existing logger. Instead, you pass in a list of zap Options, which will be applied to a newly created logger.
if `ENV` variable is set, and is anything other than "production", we put the logger in development mode.
The logger's log level flips from INFO to DEBUG and back again every time you send the `USR1` signal to the process.
This way, the client can choose to either deal with the error themselves in whatever appropriate way they want, or ust `logger.Must` if they simply want to panic if an error occurs on initialization.
logger.go
Outdated
|
||
// TestNew calls New, but returns both the logger, and an observer that can be | ||
// used to fetch and compare delivered logs. | ||
func TestNew(tb testing.TB, options ...zap.Option) (*zap.Logger, *observer.ObservedLogs) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd expect NewTest
, if all the "constructor" functions begin with New
it helps with autocompletion etc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer TestNew
, as this is supposed to a "public testing API" as described by Mitchell Hashimoto.
See:
- https://speakerdeck.com/mitchellh/advanced-testing-with-go?slide=52
- https://www.youtube.com/watch?v=yszygk1cpEc
Right now, it's only a single function, but there could be more down the line, and then it makes sense to always prefix them with Test
(and move them into testing.go
, but I didn't see the point of that for this one function, but maybe I should).
Also, in terms of autocompletion, all editors I use actually use fuzzy matching, so not sure if that's a reason to change this default.
logger.New
which returns a new Zap logger)tier
log fieldenvironment
log fieldlogger.TestNew
note: you can still easily set the tier and environment fields yourself on initialisation:
For more details on the Stackdriver log format, see: