Closed mcosta74 closed 2 years ago
@mcosta74 Thanks for the well written PR. You added docs, examples, and all the nice touches. Much appreciated.
I'm still not sure if we want to add this API, but if we do I think your approach takes the right approach. So, before I add any comments on the details I want to poll the other maintainers for their opinion.
@peterbourgon, @sagikazarmark what do you think of adding this option?
I'm not 100% sure why a fallback option is necessary. As far as I can tell, it's equivalent to the following:
logger = level.NewFilter(logger, level.AllowInfo, level.AllowByString(os.Getenv("LOG_LEVEL")))
If the string doesn't match any of the log levels, it should just be noop.
Personally, I'm not a huge fan of fallbacks in this case though. Consider the following: let's say you misconfigure the production instance and as a result debug logs will start flowing in, potentially containing PII without you even noticing.
I usually log a warning or an error whenever the log config is invalid (which is also why I manually parse log levels and match them to the appropriate log levels).
The name AllowByString
feels a bit weird. I'd go with something like Parse
.
Other than these, I don't mind adding a few utility functions if they really help.
If the string doesn't match any of the log levels, it should just be noop.
Personally, I'm not a huge fan of fallbacks in this case though. Consider the following: let's say you misconfigure the production instance and as a result debug logs will start flowing in, potentially containing PII without you even noticing.
@sagikazarmark Agree, the fallback mechanism may obfuscate a misconfiguration.
Should I apply the changes or better to wait a final decision about adding or not that function ?
The name
AllowByString
feels a bit weird. I'd go with something likeParse
.
I'm open to change the name if the approach is accepted
I've applied the changes suggested by @sagikazarmark. Let me know about the final decision.
hello @peterbourgon, I've applied all changes requested.
Proper grammar and spelling, please :) Let me know if you'd like suggestions.
Please let me know if you find better wording for the doc strings. I'm open to change.
Looks like we have an agreement. Let me implement these API
==============
Massimo Costa
Il ven 8 apr 2022, 20:16 Chris Hines @.***> ha scritto:
@.**** commented on this pull request.
In level/level.go https://github.com/go-kit/log/pull/22#discussion_r846373837:
+// ParseOption creates an Option from a string value. It might be useful in case we need to configure
+// the log level using a flag, an environment variable, a configuration file, ...
+//
+// Leading and trailing spaces are ignored and the comparison is Case Insensitive:
+// "ERROR", "Error", " Error " are accepted
+//
+// If the level parameter does not match any of the available values, the function returns a not nil error.
+func ParseOption(level string) (Option, error) {
level = strings.TrimSpace(strings.ToLower(level))
switch level {
case debugValue.name:
return AllowDebug(), nil
case infoValue.name:
return AllowInfo(), nil
case warnValue.name:
return AllowWarn(), nil
case errorValue.name:
return AllowError(), nil
default:
// return a noop Option in case of unknown level string
return nil, fmt.Errorf("invalid level: %s", level)
}
+}
🎉 Great. 🎉 I'm on board too.
— Reply to this email directly, view it on GitHub https://github.com/go-kit/log/pull/22#discussion_r846373837, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA4I7OKBLXWIID3Q36AU3CDVEBZYVANCNFSM5RYT3RZA . You are receiving this because you were mentioned.Message ID: @.***>
This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Files with Coverage Reduction | New Missed Lines | % | ||
---|---|---|---|---|
level/level.go | 1 | 99.11% | ||
<!-- | Total: | 1 | --> |
Totals | |
---|---|
Change from base Build 2065105133: | 2.5% |
Covered Lines: | 555 |
Relevant Lines: | 744 |
I think I implemented the agreed API, if the code is code we can also squash the commits
I think I implemented the agreed API, if the code is code we can also squash the commits
Thanks, @mcosta74. I will review the code sometime in the next few days. Also, thanks for you patience during the API debate.
I think I implemented the agreed API, if the code is code we can also squash the commits
Thanks, @mcosta74. I will review the code sometime in the next few days. Also, thanks for you patience during the API debate.
no problem at all, I think it was a very interesting and productive discussion. I would only suggest to create a CONTRIBUTION page (maybe with a discussion template) to clarify what are the principles to follow in case someone else wants to propose new API.
@peterbourgon I think we're just waiting for you to sign off on this since you previously requested changes.
Any update on this ?
@peterbourgon Everyone involved has approved this PR except you. I think @mcosta74 has addressed all of your feedback. Please verify and approve if you agree. Thanks.
Oops, sorry! I didn't know I was blocking.
Thanks for the contribution @mcosta74 🎉 .
Thanks for the contribution @mcosta74 🎉 .
you're welcome
Hello, are you planning to release a new version of the package ?
Sure, we can do that — v0.2.1
or v0.3.0
? I don't think we made any breaking changes, so my instinct is v0.2.1
?
My vote is v0.2.1
as well. No breaking changes, just a new feature.
Great. Assuming no objections, I'll tag a release in a day or so.
not in my hands to make decisions but, since we added a feature following the SemVer guidelines I'd go for a 0.3.0
. I'll keep the last number for bug-fixes
@mcosta74 That is a perfectly correct reading of the SemVer guidelines. But my interpretation is that only strictly applies for major version >= 1.
From semver.org:
Major version zero (0.y.z) is for initial development. Anything MAY change at any time. The public API SHOULD NOT be considered stable.
Version 1.0.0 defines the public API. The way in which the version number is incremented after this release is dependent on this public API and how it changes.
So I think it is also correct for us to do whatever we want. I don't want to suggest we should start making lots of breaking changes. I consider this module highly stable, and the API of the core log
package extremely stable. We haven't made any breaking changes that I recall in ~5 years and I don't want to start doing so.
But if we stay on major version 0 per https://github.com/go-kit/log/discussions/24#discussioncomment-2649183, then I think it is fair and appropriate to adapt the y
semver number for "biggish" changes and the z
number for "smallish" changes. I think it is more about signaling to consumers how much they should pay attention before upgrading.
@ChrisHines Thanks for the explanation. Whit this in mind I agree that 0.2.1
is the right choice
Hi @peterbourgon any ETA about the release? I'm using the "unreleased" version in a project we're building but I'd like to use a "released" one
My apologies for the delay. v0.2.1 is now released. Please let me know if there are any issues.
@peterbourgon, no problem. Thank you again for the products you give to the community.
This PR allows to configure the allowed log levels from a string.
Closes: #18
Use Case:
Read the allowed log levels reading environment variable