Skip to content

Commit c365eb9

Browse files
committed
Fix log lines with badkey
When slog receives an odd number of key-value pairs, it prints a \'!BADKEY\' string. This commit fixes some occurrences of this
1 parent 9b55044 commit c365eb9

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

docs/examples/getting_started/main.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import (
44
"context"
55
"errors"
66
"fmt"
7-
rmq "github.com/rabbitmq/rabbitmq-amqp-go-client/pkg/rabbitmqamqp"
87
"time"
8+
9+
rmq "github.com/rabbitmq/rabbitmq-amqp-go-client/pkg/rabbitmqamqp"
910
)
1011

1112
func main() {
@@ -44,7 +45,7 @@ func main() {
4445
// this is valid for the connection lifecycle
4546
amqpConnection.NotifyStatusChange(stateChanged)
4647

47-
rmq.Info("AMQP connection opened.\n")
48+
rmq.Info("AMQP connection opened")
4849
// Create the management interface for the connection
4950
// so we can declare exchanges, queues, and bindings
5051
management := amqpConnection.Management()
@@ -94,21 +95,21 @@ func main() {
9495
deliveryContext, err := consumer.Receive(ctx)
9596
if errors.Is(err, context.Canceled) {
9697
// The consumer was closed correctly
97-
rmq.Info("[Consumer]", "consumer closed. Context", err)
98+
rmq.Info("[Consumer] Consumer closed", "context", err)
9899
return
99100
}
100101
if err != nil {
101102
// An error occurred receiving the message
102-
rmq.Error("[Consumer]", "Error receiving message", err)
103+
rmq.Error("[Consumer] Error receiving message", "error", err)
103104
return
104105
}
105106

106-
rmq.Info("[Consumer]", "Received message",
107+
rmq.Info("[Consumer] Received message", "message",
107108
fmt.Sprintf("%s", deliveryContext.Message().Data))
108109

109110
err = deliveryContext.Accept(context.Background())
110111
if err != nil {
111-
rmq.Error("Error accepting message", err)
112+
rmq.Error("[Consumer] Error accepting message", "error", err)
112113
return
113114
}
114115
}
@@ -172,39 +173,39 @@ func main() {
172173
err = management.Unbind(context.TODO(), bindingPath)
173174

174175
if err != nil {
175-
rmq.Error("Error unbinding: %v\n", err)
176+
rmq.Error("Error unbinding", "error", err)
176177
return
177178
}
178179

179180
err = management.DeleteExchange(context.TODO(), exchangeInfo.Name())
180181
if err != nil {
181-
rmq.Error("Error deleting exchange: %v\n", err)
182+
rmq.Error("Error deleting exchange", "error", err)
182183
return
183184
}
184185

185186
// Purge the queue
186187
purged, err := management.PurgeQueue(context.TODO(), queueInfo.Name())
187188
if err != nil {
188-
rmq.Error("Error purging queue: %v\n", err)
189+
rmq.Error("Error purging queue", "error", err)
189190
return
190191
}
191-
rmq.Info("Purged %d messages from the queue.\n", purged)
192+
rmq.Info("Purged messages from the queue", "count", purged)
192193

193194
err = management.DeleteQueue(context.TODO(), queueInfo.Name())
194195
if err != nil {
195-
rmq.Error("Error deleting queue: %v\n", err)
196+
rmq.Error("Error deleting queue", "error", err)
196197
return
197198
}
198199

199200
// Close all the connections. but you can still use the environment
200201
// to create new connections
201202
err = env.CloseConnections(context.Background())
202203
if err != nil {
203-
rmq.Error("Error closing connection: %v\n", err)
204+
rmq.Error("Error closing connection", "error", err)
204205
return
205206
}
206207

207-
rmq.Info("AMQP connection closed.\n")
208+
rmq.Info("AMQP connection closed")
208209
// not necessary. It waits for the status change to be printed
209210
time.Sleep(100 * time.Millisecond)
210211
close(stateChanged)

pkg/rabbitmqamqp/amqp_connection.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ func (a *AmqpConnection) open(ctx context.Context, address string, connOptions *
440440
return fmt.Errorf("failed to open TLS connection: %w", err)
441441
}
442442
if err != nil {
443-
Error("Failed to open connection", ExtractWithoutPassword(address), err, "ID", connOptions.Id)
443+
Error("Failed to open connection", "url", ExtractWithoutPassword(address), "error", err, "ID", connOptions.Id)
444444
return fmt.Errorf("failed to open connection: %w", err)
445445
}
446446
a.properties = azureConnection.Properties()

pkg/rabbitmqamqp/amqp_environment.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ package rabbitmqamqp
33
import (
44
"context"
55
"fmt"
6-
"github.com/Azure/go-amqp"
76
"sync"
87
"sync/atomic"
8+
9+
"github.com/Azure/go-amqp"
910
)
1011

1112
type TEndPointStrategy int
@@ -83,7 +84,7 @@ func (e *Environment) NewConnection(ctx context.Context) (*AmqpConnection, error
8384
}
8485
connection, err := Dial(ctx, addr.Address, cloned)
8586
if err != nil {
86-
Error("Failed to open connection", ExtractWithoutPassword(addr.Address), err)
87+
Error("Failed to open connection", "url", ExtractWithoutPassword(addr.Address), "error", err)
8788
lastError = err
8889
continue
8990
}

0 commit comments

Comments
 (0)