-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Remove logrus #50829
Remove logrus #50829
Conversation
55173a4
to
3a6dea2
Compare
737af4b
to
7bcf7bb
Compare
0a31c37
to
9ed50e3
Compare
@@ -114,13 +113,6 @@ func (s *handleState) appendAttr(a slog.Attr) bool { | |||
} | |||
} | |||
return nonEmpty | |||
case logrus.Fields: |
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.
There is nothing including these fields in slog output so this is not needed.
lib/utils/log/levels.go
Outdated
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.
This was moved into utils/log/slog.go
lib/utils/log/logrus_formatter.go
Outdated
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 items deleted were moved into lib/utils/log/slog.go to facilitate removing this file in the future.
) | ||
|
||
// TODO(tross/noah): Remove once go-spiff has a slog<->workloadapi.Logger adapter. |
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.
FYI @strideynet. If you have a better solution to this in the short term I'm all ears.
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 have a ticket w/ go-spiffe to add slog support - spiffe/go-spiffe#281 - perhaps link this ticket here?
What you've done here is good for now!
d02cea6
to
f9c7fa5
Compare
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.
Nice! We are almost 100% logrus-free!
//nolint:sloglint // msg cannot be constant | ||
l.l.DebugContext(context.Background(), fmt.Sprintf(format, args...)) |
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:
l.log(slog.LevelDebug, format, args...)
and implement the l.log function so it centralized the nolint / fmt.Sprintf logic?
The only remaining use of logrus is from integrations, which is unfortunately imported by teleport.e, and prevents logrus from being moved to an indirect dependency. The logrus formatter and initialization of the logrus logger will remain in place until integrations is using slog. To prevent any accidental inclusions of logrus within the teleport module the depguard rules have been updated to prohibit importing logrus. The rules also include prohibit a few common log packages that tools like gopls might automatically import.
f9c7fa5
to
e0433c8
Compare
Consolidates configuring of global loggers to a single function. This is mainly to facilitate configuring the logger for teleport scp, but will also allow us to remove the copy of logger initialization that currently exists in integrations/lib/logger.
c31858f
to
839b31b
Compare
// sharedWriter is an [io.Writer] implementation that protects | ||
// writes with a mutex. This allows a single [io.Writer] to be shared | ||
// by both logrus and slog without their output clobbering each other. | ||
type sharedWriter struct { |
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.
So what hapeened / will happen to lib/utils/log.SharedWriter
? Is it being moved here? Why don't I see it being deleted in this PR?
(Also, since this file is already huge, can this struct remain in a separate one?)
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.
log.SharedWriter
is going to be removed with the logrus formatter once we are no longer using logrus. I opted to copy it locally here preemptively since a little bit of copying is better than a little bit of dependency.
cfg.Console = io.Discard // disable console printing | ||
case "stdout", "out", "1": | ||
w = os.Stdout | ||
case "stderr", "error", "2", "stdout", "out", "1": |
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'm having a hard time understanding what's going on here. Why do we disable console printing when the user wants to print to the console? I know it wasn't commented in the original code either, but I still think it warrants a word or two.
The documentation comments of Config.Console
and Config.Logger
don't help too much, either, as they both sound like serving roughly the same purpose.
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.
Looking at Console more closely, I don't actually see it being used anywhere. For now I'm going to leave this as is and in a follow up PR I will remove it entirely.
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 keep the cases for ""
and teleport.Syslog
in the meantime? Is the case for teleport.Syslog
obsolete too?
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.
""
and teleport.Syslog
are handled by log.Initialize.
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.
Follow up PRs to remove Console:
cfg.Console = io.Discard // disable console printing | ||
case "stdout", "out", "1": | ||
w = os.Stdout | ||
case "stderr", "error", "2", "stdout", "out", "1": |
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 keep the cases for ""
and teleport.Syslog
in the meantime? Is the case for teleport.Syslog
obsolete too?
|
||
// ValidateFields ensures the provided fields map to the allowed fields. An error | ||
// is returned if any of the fields are invalid. | ||
func ValidateFields(formatInput []string) (result []string, err error) { |
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.
Could this be made private and made a responsibility of Initialize? Perhaps after the duplicated code on integrations/ is removed?
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.
Possibly. I will look into it once the integrations changes are made.
The only remaining use of logrus is from integrations, which is unfortunately imported by teleport.e, and prevents logrus from being moved to an indirect dependency. The logrus formatter and initialization of the logrus logger will remain in place until integrations is using slog. To prevent any accidental inclusions of logrus within the teleport module the depguard rules have been updated to prohibit importing logrus. The rules also include prohibit a few common log packages that tools like gopls might automatically import.
$ go mod why github.com/sirupsen/logrus # github.com/sirupsen/logrus github.com/gravitational/teleport/integrations/access/common/auth github.com/sirupsen/logrus
Includes https://github.com/gravitational/teleport.e/pull/5807
Depends on #50805