Skip to content
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

Client example: Use instance logger instead of global logger #34

Merged
merged 1 commit into from
Jan 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions example_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ func New(name string, addr string) *Session {
func (session *Session) handleReconnect(addr string) {
for {
session.isReady = false
log.Println("Attempting to connect")
session.logger.Println("Attempting to connect")

conn, err := session.connect(addr)

if err != nil {
log.Println("Failed to connect. Retrying...")
session.logger.Println("Failed to connect. Retrying...")

select {
case <-session.done:
Expand All @@ -116,7 +116,7 @@ func (session *Session) connect(addr string) (*amqp.Connection, error) {
}

session.changeConnection(conn)
log.Println("Connected!")
session.logger.Println("Connected!")
return conn, nil
}

Expand All @@ -129,7 +129,7 @@ func (session *Session) handleReInit(conn *amqp.Connection) bool {
err := session.init(conn)

if err != nil {
log.Println("Failed to initialize channel. Retrying...")
session.logger.Println("Failed to initialize channel. Retrying...")

select {
case <-session.done:
Expand All @@ -143,10 +143,10 @@ func (session *Session) handleReInit(conn *amqp.Connection) bool {
case <-session.done:
return true
case <-session.notifyConnClose:
log.Println("Connection closed. Reconnecting...")
session.logger.Println("Connection closed. Reconnecting...")
return false
case <-session.notifyChanClose:
log.Println("Channel closed. Re-running init...")
session.logger.Println("Channel closed. Re-running init...")
}
}
}
Expand Down Expand Up @@ -179,7 +179,7 @@ func (session *Session) init(conn *amqp.Connection) error {

session.changeChannel(ch)
session.isReady = true
log.Println("Setup!")
session.logger.Println("Setup!")

return nil
}
Expand Down