Skip to content

Commit

Permalink
Merge pull request #340 from Shopify/broker-close-logging
Browse files Browse the repository at this point in the history
Reduce logging on broker close
  • Loading branch information
eapache committed Mar 12, 2015
2 parents 7a13c37 + 4f7be25 commit 2adffeb
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,9 @@ func (b *Broker) Connected() (bool, error) {
return b.conn != nil, b.connErr
}

func (b *Broker) Close() (err error) {
func (b *Broker) Close() error {
b.lock.Lock()
defer b.lock.Unlock()
defer func() {
if err == nil {
Logger.Printf("Closed connection to broker %s\n", b.addr)
} else {
Logger.Printf("Failed to close connection to broker %s: %s\n", b.addr, err)
}
}()

if b.conn == nil {
return ErrNotConnected
Expand All @@ -114,7 +107,7 @@ func (b *Broker) Close() (err error) {
close(b.responses)
<-b.done

err = b.conn.Close()
err := b.conn.Close()

b.conn = nil
b.connErr = nil
Expand All @@ -123,7 +116,13 @@ func (b *Broker) Close() (err error) {

atomic.StoreInt32(&b.opened, 0)

return
if err == nil {
Logger.Printf("Closed connection to broker %s\n", b.addr)
} else {
Logger.Printf("Error while closing connection to broker %s: %s\n", b.addr, err)
}

return err
}

// ID returns the broker ID retrieved from Kafka's metadata, or -1 if that is not known.
Expand Down

0 comments on commit 2adffeb

Please sign in to comment.