-
Notifications
You must be signed in to change notification settings - Fork 503
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
replacing logrus with slog v1 #2010
base: main
Are you sure you want to change the base?
Conversation
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.
Superficial review
@JodhwaniMadhur the idea here is correct: we should replace logrus with log/slog. However, the approach should be as follows:
|
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.
I assume this doesn't compile/doesn't work as intended at the moment does it?
Nope, it doesn't. But will take care of everything. thanks for all the suggestions. |
But then in the entry we have Severity coming in as logrus.Level which indeed should be then a generic levels decided by us or we switch to slog.Level, isn't it? and severity is outside of entry |
…nto replacing-logrus
can anyone guide me as to how I should modify the Severity function? as it was designed for logrus but for slog the TestSeverity fails for logrus, the levels are but for slog the levels are: |
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.
As to your question, if you look at the entry interface, we weren't using all of logrus's levels, we also were just using debug/info/warn/error, so let's just keep those.
LogOps | ||
FormattedLogOps | ||
ContextualLogOps | ||
SystemLogger | ||
} |
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.
We should keep this interface exactly the same and just implement it in terms of slog, why create all of the new methods above if they were not being used?
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.
Even if I remove the rest, I will have to keep them in a separate interface and take those interfaces in entry since if I write all functions inside entry, the linter in the pipeline gives error for interfacebloat
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.
As for the extra methods, I can remove those but the problem for logrus vs slog levels and problems in Severity due to this still remains
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.
As for the extra methods, I can remove those but the problem for logrus vs slog levels and problems in Severity due to this still remains
I'm not sure how they still remain, all you need to do is create a separate file that implements Entry in terms of log/slog?
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.
Here's an example:
type slogger struct {
l *slog.Logger
}
// Debugf implements Entry.
func (s *slogger) Debugf(format string, args ...any) {
s.l.Debug(fmt.Sprintf(format, args...))
}
// Errorf implements Entry.
func (s *slogger) Errorf(format string, args ...any) {
s.l.Error(fmt.Sprintf(format, args...))
}
For severity in the errors
package, you can continue to use logrus levels, or you can change it to slog, or better yet create an abstraction in the athens log package because the error package shouldn't import a third party lib
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.
An abstraction is preferred, imo.
I would expect to see a go.mod/go.sum change that shows we removed Logrus as a dependency |
What is the problem I am trying to address?
Removing logrus and implementing slog
How is the fix applied?
Replaced logrus.
Implemented functions that are missing in slog but were present in slog
What GitHub issue(s) does this PR fix or close?
Fixes #1890