uber-go / zap

Blazing fast, structured, leveled logging in Go.
https://pkg.go.dev/go.uber.org/zap
MIT License
22.1k stars 1.44k forks source link

zapcore: add warning as Level #1429

Closed florianl closed 5 months ago

florianl commented 7 months ago

Some packages set their value for WarnLevel to "warning". For easier integration add "warning" as accepted WarnLevel.

Example for a package that is using "warning": https://github.com/sirupsen/logrus/blob/dd1b4c2e81afc5c255f216a722b012ed26be57df/logrus.go#L68

CLAassistant commented 7 months ago

CLA assistant check
All committers have signed the CLA.

florianl commented 7 months ago

Friendly ping for feedback to @abhinav or @JacobOaks . Thanks in advance :pray:

r-hang commented 7 months ago

Hey @florianl, I think this change incurs some technical debt for a small amount of flexibility. The current level MarshalText logic is simplified because there is either a capitalized or lower case representation of the each level, where the level is represented in a consistent tense.

From my perspective, the special check case in level_test.go makes the level test code a bit more difficult to main.

florianl commented 7 months ago

Hey @r-hang thanks for the feedback! I agree with you, that current level MarshalText logic is simplified and should stay that way.

There are cases where this packages is expected to handle input, that is generated from other packages, that are using the same levels, but slightly different level text - warning instead of warn. Currently this package is not able to pick up these slightly differences. In such cases where this package is expected to handle input with level warning, it will ignore this level, and will instead use level=info - which is not correct. The intention of this PR is, that this package is able to handle input that originates from other sources and transparently uses the correct level.

codecov[bot] commented 7 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 98.70%. Comparing base (b15585b) to head (cb50e12). Report is 7 commits behind head on master.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #1429 +/- ## ======================================= Coverage 98.69% 98.70% ======================================= Files 53 53 Lines 2997 3014 +17 ======================================= + Hits 2958 2975 +17 Misses 31 31 Partials 8 8 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

florianl commented 7 months ago

@r-hang what do you think about having a dedicated test for unmarshaling warning rather mixing it with the existing TestLevelText? This should decrease the maintenance level in the test you have mentioned.

florianl commented 6 months ago

@abhinav or @JacobOaks or @r-hang with https://github.com/uber-go/zap/pull/1429/commits/126ea63be89efd6961a7678da70689e64fabe35f I have moved the test to guarantee compatability to a dedicated sub test. Please let me know, if this works for you.

florianl commented 5 months ago

friendly ping to @abhinav or @JacobOaks or @r-hang - do you have some feedback?

r-hang commented 5 months ago

Makes sense to me @florianl! Thanks for helping keep our tests more maintainable and sorry for the delay.