-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Make level configurable for NewStdLog. (#439) #487
Conversation
Codecov Report
@@ Coverage Diff @@
## master #487 +/- ##
==========================================
+ Coverage 97.16% 97.19% +0.02%
==========================================
Files 37 37
Lines 2221 2243 +22
==========================================
+ Hits 2158 2180 +22
Misses 56 56
Partials 7 7
Continue to review full report at Codecov.
|
@delicb Sorry for the long delay reviewing this! Changes and test coverage look great. I'm going to push a commit with a few small nits (e.g., Thank you for the contribution! |
@akshayjshah Ah, sure, Thank you for accepting PR. |
🤦♂️ I completely forgot about this - I'm so sorry, @delicb! I'll merge this today. |
With this change new function is added called NewStdLogAt. It has same behaviour as NewStdLog, but it allows providing log level to use by returned *log.Logger.
Use the `NoError` testing helpers instead of directly comparing errors to nil.
54cb0ed
to
4fe6514
Compare
@akshayjshah Was there a specific reason to not additionally make this change (log level configurable) for |
Nope, you're welcome to open a PR with |
@akshayjshah Opened #508. |
With this change new function is added called
NewStdLogAt
. It has samebehaviour as NewStdLog, but it allows providing log level to use by
returned
*log.Logger
.Couple of things to note:
*zap.Logger.Log(Level, string, …zapcore.Fields)
in addition toDebug
,Info
, etc. I understand if you do not want to introduce it, but if you are opened to it, I can add it and adapt implementation.loggerWriter
is changed to accept function to use, so that decision which function should be used is elsewhere. Existing code is compatible, since default wasInfo
and that is passed. This can be other way around -loggerWriter
can have both logger and level and decide which function to call duringWrite
execution, but I do not really like idea of executing switch case every timeWrite
is called.TestNewStdLog
can be reused. It might be possible to generalize this to table-driven test, but DPanic, Panic and Fatal levels have special handling, so it might be a bit long. I prefer it the way I wrote it, but I am opened to changing it to table driven test if that is preferred.