Skip to content

Commit

Permalink
Remaning logger references
Browse files Browse the repository at this point in the history
  • Loading branch information
badslug committed Jul 13, 2023
1 parent a86121b commit b0fd0ed
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
18 changes: 10 additions & 8 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,12 @@ func (c *Client) Reconnect() {
// Send calls that haven't been confirmed - may not have been sent
// and effects should be idempotent
for _, call := range c.calls {
IgnoreErr(c.Send(NewMethod(call.ID, call.ServiceMethod, call.Args.([]interface{}))), "resend method")
IgnoreErr(c.Send(NewMethod(call.ID, call.ServiceMethod, call.Args.([]interface{}))), "resend method", c.l)
}

// Resend subscriptions and patch up collections
for _, sub := range c.subs {
IgnoreErr(c.Send(NewSub(sub.ID, sub.ServiceMethod, sub.Args.([]interface{}))), "resend sub")
IgnoreErr(c.Send(NewSub(sub.ID, sub.ServiceMethod, sub.Args.([]interface{}))), "resend sub", c.l)
}
}

Expand All @@ -259,6 +259,7 @@ func (c *Client) Subscribe(subName string, done chan *Call, args ...interface{})
call.ServiceMethod = subName
call.Args = args
call.Owner = c
call.l = c.l

if done == nil {
done = make(chan *Call, 10) // buffered.
Expand All @@ -278,7 +279,7 @@ func (c *Client) Subscribe(subName string, done chan *Call, args ...interface{})
subArgs := make([]interface{}, len(args))
copy(subArgs, args)

IgnoreErr(c.Send(NewSub(call.ID, subName, args)), "send sub")
IgnoreErr(c.Send(NewSub(call.ID, subName, args)), "send sub", c.l)

return call
}
Expand All @@ -305,6 +306,7 @@ func (c *Client) Go(serviceMethod string, done chan *Call, args ...interface{})
call.ServiceMethod = serviceMethod
call.Args = args
call.Owner = c
call.l = c.l
if done == nil {
done = make(chan *Call, 10) // buffered.
} else {
Expand All @@ -319,7 +321,7 @@ func (c *Client) Go(serviceMethod string, done chan *Call, args ...interface{})
call.Done = done
c.calls[call.ID] = call

IgnoreErr(c.Send(NewMethod(call.ID, serviceMethod, args)), "send method")
IgnoreErr(c.Send(NewMethod(call.ID, serviceMethod, args)), "send method", c.l)

return call
}
Expand Down Expand Up @@ -383,7 +385,7 @@ func (c *Client) Close() {

// Close websocket
if c.ws != nil {
IgnoreErr(c.ws.Close(), "close ws")
IgnoreErr(c.ws.Close(), "close ws", c.l)
c.ws = nil
}

Expand Down Expand Up @@ -470,7 +472,7 @@ func (c *Client) start(ws *websocket.Conn, connect *Connect) {
c.readSocketStats = NewReaderStats(c.ws)
c.readStats.Reader = c.readSocketStats

IgnoreErr(c.Send(connect), "send connect")
IgnoreErr(c.Send(connect), "send connect", c.l)
}

// inboxManager pulls messages from the inbox and routes them to appropriate
Expand Down Expand Up @@ -507,9 +509,9 @@ func (c *Client) inboxManager() {
// We received a ping - need to respond with a pong
id, ok := msg["id"]
if ok {
IgnoreErr(c.Send(NewPong(id.(string))), "send id ping")
IgnoreErr(c.Send(NewPong(id.(string))), "send id ping", c.l)
} else {
IgnoreErr(c.Send(NewPong("")), "send empty ping")
IgnoreErr(c.Send(NewPong("")), "send empty ping", c.l)
}
c.pingsIn++
case "pong":
Expand Down
10 changes: 6 additions & 4 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ type Call struct {
Error error // After completion, the error status.
Done chan *Call // Strobes when call is complete.
Owner *Client // Client that owns the method call

l *log.Entry // logger to use for all logs
}

// done removes the call from any owners and strobes the done channel with itself.
Expand All @@ -65,13 +67,13 @@ func (call *Call) done() {
default:
// We don't want to block here. It is the caller's responsibility to make
// sure the channel has enough buffer space. See comment in Go().
log.Debug("rpc: discarding Call reply due to insufficient Done chan capacity")
call.l.Debug("rpc: discarding Call reply due to insufficient Done chan capacity")
}
}

// IgnoreErr logs an error if it occurs and ignores it.
func IgnoreErr(err error, msg string) {
func IgnoreErr(err error, msg string, l *log.Entry) {
if err != nil {
log.WithError(err).Debug(msg)
l.WithError(err).Debug(msg)
}
}
}

0 comments on commit b0fd0ed

Please sign in to comment.