-
Notifications
You must be signed in to change notification settings - Fork 112
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
Allow eggos implementations to programatically set log levels #96
Conversation
When running applications on environments where there is no environment, calls to os.Setenv to set a loglevel have inconsistent results. Similarly, setting this environment variable before the first log event, and thus making that call moot, is racy. Instead, then, export log levels, drop the potential stutter in log.LogLvl to log.Level, and allow implementations/ callers of this package to set a log level accordingly, while maintaining the default behaviour
log/log.go
Outdated
) | ||
|
||
var ( | ||
loglvl int | ||
loglvlonce sync.Once | ||
Level int |
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.
Maybe a setter would be better, like SetLogLevel
?
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.
Sure thing, if that's the way you'd prefer it. It'd still be nice to have this public to be able to inspect the value- would you prefer a getter, or the naked var?
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.
Gopher prefer naked var 😄
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.
My worry is that adding the setter, then, adds complexity and can be bypassed by setting directly on the naked value.
I'll make sure that the setter is well documented to explain that it does additional checking to make sure the specified level is a valid level. That's probably the best of all worlds!
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.
The current log package implementation is relatively simple, I think there is no problem if you implement it in a simple way.
@icexin ♻️ I've written a setter with bounds checking (with some tests) and made it accept an explicit log level type. I've left the |
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.
LGTM
When running applications on platforms where there is no environment, calls to
os.Setenv
to set a loglevel have inconsistent results. Similarly, setting this environment variable before the first log event, and thus making that call moot, is racy.Instead, then, export log levels, drop the potential stutter in
log.LogLvl
tolog.Level
, and allow implementations/ callers of this package to set a log level accordingly, while maintaining the default behaviour