[ffapi] Ensure Default Log Level is Set in Handler #203
+3
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Following up from #201
Its a bit awkward - we added a private field to
HandlerFactory. ButHandlerFactorydoesn't have a properNewfunc orInitto guarantee that internal log level field is set. If the log level field is not set and defaults to 0, thenlogruspanics on the first log message.For most clients, they let
APIServerconstruct and setup aHandlerFactory, so they are unaffected. But if anyone was initializing their ownHandlerFactoryand doesn't then callSetAPIEntryLoggingLevel, it would panic.We don't want to check for 0 on every API request, as that would be inefficient, so we check when we construct
APIWrapper's who would depend on the log level to not be nil in order to fix this.In a 2.0 of ff-common, we should likely make all fields of
HandlerFactoryprivate, have aNewfunc, and use the functional options or builder pattern to provide a variadic way of setting all the possible fields (which is what a struct with public fields and no constructor feels like, but has potential for bugs like this one).