-
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
Convert lib/reversetunnel to use slog #50362
Conversation
for { | ||
select { | ||
case <-s.ctx.Done(): | ||
s.logger.WithError(s.ctx.Err()).Debug("Context is closing.") |
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.
Can we check the s.ctx.Err() != nil
log if true?
log := logger | ||
if roundtrip != 0 { | ||
log = logger.WithField("latency", roundtrip.String()) | ||
log = logger.With("latency", logutils.StringerAttr(roundtrip)) | ||
} | ||
log.Debugf("Ping <- %v", rconn.conn.RemoteAddr()) | ||
log.DebugContext(ctx, "Received ping request", "remote_addr", logutils.StringerAttr(rconn.conn.RemoteAddr())) |
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.
Is there a better way to do conditional fields in 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.
The only other option I can think of is to use a slice and only append attributes if they should be included in the output.
@@ -788,9 +802,9 @@ func (s *localSite) handleHeartbeat(rconn *remoteConn, ch ssh.Channel, reqC <-ch | |||
|
|||
log := logger | |||
if roundtrip != 0 { | |||
log = logger.WithField("latency", roundtrip.String()) | |||
log = logger.With("latency", logutils.StringerAttr(roundtrip)) |
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.
Sould we add special handling for time.Duration
to our handlers so we don't have to do this every time, kinda like we do for 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.
Possibly, the other option is to use slog.Duration("latency", roundtrip)
.
1708df7
to
2444661
Compare
2444661
to
c37d452
Compare
No description provided.