Skip to content

Commit cf19dad

Browse files
committed
adapt log messages for new logger interface
1 parent 0be196f commit cf19dad

File tree

12 files changed

+65
-65
lines changed

12 files changed

+65
-65
lines changed

cluster.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ func (cfg *ClusterConfig) translateAddressPort(addr net.IP, port int, logger Str
344344
return addr, port
345345
}
346346
newAddr, newPort := cfg.AddressTranslator.Translate(addr, port)
347-
logger.Debug("translating address '%v:%d' to '%v:%d'",
347+
logger.Debug("Translating address.",
348348
newLogFieldIp("old_addr", addr), newLogFieldInt("old_port", port),
349349
newLogFieldIp("new_addr", newAddr), newLogFieldInt("new_port", newPort))
350350
return newAddr, newPort

conn.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ func (c *Conn) processFrame(ctx context.Context, r io.Reader) error {
700700
delete(c.calls, head.stream)
701701
c.mu.Unlock()
702702
if call == nil || !ok {
703-
c.logger.Warning("received response for stream which has no handler: header=%v", newLogFieldString("header", head.String()))
703+
c.logger.Warning("Received response for stream which has no handler.", newLogFieldString("header", head.String()))
704704
return c.discardFrame(r, head)
705705
} else if head.stream != call.streamID {
706706
panic(fmt.Sprintf("call has incorrect streamID: got %d expected %d", call.streamID, head.stream))
@@ -1315,18 +1315,18 @@ func (c *Conn) execInternal(ctx context.Context, req frameBuilder, tracer Tracer
13151315
return resp.framer, nil
13161316
case <-timeoutCh:
13171317
close(call.timeout)
1318-
c.logger.Debug("Request timed out on connection %v (%v)",
1318+
c.logger.Debug("Request timed out on connection.",
13191319
newLogFieldString("host_id", c.host.HostID()), newLogFieldIp("addr", c.host.ConnectAddress()))
13201320
c.handleTimeout()
13211321
return nil, ErrTimeoutNoResponse
13221322
case <-ctxDone:
1323-
c.logger.Debug("Request failed because context elapsed out on connection %v (%v): %v",
1323+
c.logger.Debug("Request failed because context elapsed out on connection.",
13241324
newLogFieldString("host_id", c.host.HostID()), newLogFieldIp("addr", c.host.ConnectAddress()),
13251325
newLogFieldError("ctx_err", ctx.Err()))
13261326
close(call.timeout)
13271327
return nil, ctx.Err()
13281328
case <-c.ctx.Done():
1329-
c.logger.Debug("Request failed because connection closed %v (%v).",
1329+
c.logger.Debug("Request failed because connection closed.",
13301330
newLogFieldString("host_id", c.host.HostID()), newLogFieldIp("addr", c.host.ConnectAddress()))
13311331
close(call.timeout)
13321332
return nil, ErrConnectionClosed
@@ -1668,7 +1668,7 @@ func (c *Conn) executeQuery(ctx context.Context, qry *Query) *Iter {
16681668
iter := &Iter{framer: framer}
16691669
if err := c.awaitSchemaAgreement(ctx); err != nil {
16701670
// TODO: should have this behind a flag
1671-
c.logger.Warning("error while awaiting for schema agreement after a schema change event: %v", newLogFieldError("err", err))
1671+
c.logger.Warning("Error while awaiting for schema agreement after a schema change event.", newLogFieldError("err", err))
16721672
}
16731673
// dont return an error from this, might be a good idea to give a warning
16741674
// though. The impact of this returning an error would be that the cluster
@@ -1920,7 +1920,7 @@ func (c *Conn) awaitSchemaAgreement(ctx context.Context) (err error) {
19201920
goto cont
19211921
}
19221922
if !isValidPeer(host) || host.schemaVersion == "" {
1923-
c.logger.Warning("invalid peer or peer with empty schema_version: peer=%s", newLogFieldIp("peer", host.ConnectAddress()))
1923+
c.logger.Warning("Invalid peer or peer with empty schema_version.", newLogFieldIp("peer", host.ConnectAddress()))
19241924
continue
19251925
}
19261926

conn_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ func TestDNSLookupConnected(t *testing.T) {
206206
t.Fatal("CreateSession() should have connected")
207207
}
208208

209-
if !strings.Contains(log.String(), "gocql: dns error") {
209+
if !strings.Contains(log.String(), "gocql: DNS error") {
210210
t.Fatalf("Expected to receive dns error log message - got '%s' instead", log.String())
211211
}
212212
}
@@ -230,7 +230,7 @@ func TestDNSLookupError(t *testing.T) {
230230
t.Fatal("CreateSession() should have returned an error")
231231
}
232232

233-
if !strings.Contains(log.String(), "gocql: dns error") {
233+
if !strings.Contains(log.String(), "gocql: DNS error") {
234234
t.Fatalf("Expected to receive dns error log message - got '%s' instead", log.String())
235235
}
236236

@@ -357,7 +357,7 @@ func (o *testQueryObserver) ObserveQuery(ctx context.Context, q ObservedQuery) {
357357
host := q.Host.ConnectAddress().String()
358358
o.metrics[host] = q.Metrics
359359
if o.verbose {
360-
o.logger.Debug("Observed query %q. Returned %v rows, took %v on host %q with %v attempts and total latency %v. Error: %q\n",
360+
o.logger.Debug("Observed query.",
361361
newLogFieldString("stmt", q.Statement),
362362
newLogFieldInt("rows", q.Rows),
363363
newLogFieldString("duration", q.End.Sub(q.Start).String()),

connectionpool.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -493,19 +493,19 @@ func (pool *hostConnPool) logConnectErr(err error) {
493493
if opErr, ok := err.(*net.OpError); ok && (opErr.Op == "dial" || opErr.Op == "read") {
494494
// connection refused
495495
// these are typical during a node outage so avoid log spam.
496-
pool.logger.Debug("unable to dial %s (%s): %v",
496+
pool.logger.Debug("Pool unable to establish a connection to host.",
497497
newLogFieldIp("host_addr", pool.host.ConnectAddress()), newLogFieldString("host_id", pool.host.HostID()), newLogFieldError("err", err))
498498
} else if err != nil {
499499
// unexpected error
500-
pool.logger.Debug("failed to connect to %s (%s) due to error: %v",
500+
pool.logger.Debug("Pool failed to connect to host due to error.",
501501
newLogFieldIp("host_addr", pool.host.ConnectAddress()), newLogFieldString("host_id", pool.host.HostID()), newLogFieldError("err", err))
502502
}
503503
}
504504

505505
// transition back to a not-filling state.
506506
func (pool *hostConnPool) fillingStopped(err error) {
507507
if err != nil {
508-
pool.logger.Warning("connection pool filling failed %s (%s): %v",
508+
pool.logger.Warning("Connection pool filling failed.",
509509
newLogFieldIp("host_addr", pool.host.ConnectAddress()), newLogFieldString("host_id", pool.host.HostID()), newLogFieldError("err", err))
510510
// wait for some time to avoid back-to-back filling
511511
// this provides some time between failed attempts
@@ -522,7 +522,7 @@ func (pool *hostConnPool) fillingStopped(err error) {
522522

523523
// if we errored and the size is now zero, make sure the host is marked as down
524524
// see https://github.com/apache/cassandra-gocql-driver/issues/1614
525-
pool.logger.Debug("conns of pool after stopped %s (%s): %v",
525+
pool.logger.Debug("Logging number of connections of pool after filling stopped.",
526526
newLogFieldIp("host_addr", host.ConnectAddress()), newLogFieldString("host_id", host.HostID()), newLogFieldInt("count", count))
527527
if err != nil && count == 0 {
528528
if pool.session.cfg.ConvictionPolicy.AddFailure(err, host) {
@@ -579,7 +579,7 @@ func (pool *hostConnPool) connect() (err error) {
579579
break
580580
}
581581
}
582-
pool.logger.Warning("connection failed %s (%s): %v, reconnecting with %v",
582+
pool.logger.Warning("Pool failed to connect to host. Reconnecting according to the reconnection policy.",
583583
newLogFieldIp("host", pool.host.ConnectAddress()),
584584
newLogFieldString("host_id", pool.host.HostID()),
585585
newLogFieldError("err", err),
@@ -630,7 +630,7 @@ func (pool *hostConnPool) HandleError(conn *Conn, err error, closed bool) {
630630
return
631631
}
632632

633-
pool.logger.Info("pool connection error %v: %v",
633+
pool.logger.Info("Pool connection error.",
634634
newLogFieldString("addr", conn.addr), newLogFieldError("err", err))
635635

636636
// find the connection index

control.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func (c *controlConn) heartBeat() {
105105

106106
resp, err := c.writeFrame(&writeOptionsFrame{})
107107
if err != nil {
108-
c.session.logger.Debug("control connection heartbeat failed: %v.", newLogFieldError("err", err))
108+
c.session.logger.Debug("Control connection failed to send heartbeat.", newLogFieldError("err", err))
109109
goto reconn
110110
}
111111

@@ -115,10 +115,10 @@ func (c *controlConn) heartBeat() {
115115
sleepTime = 5 * time.Second
116116
continue
117117
case error:
118-
c.session.logger.Debug("control connection heartbeat failed: %v.", newLogFieldError("err", actualResp))
118+
c.session.logger.Debug("Control connection heartbeat failed.", newLogFieldError("err", actualResp))
119119
goto reconn
120120
default:
121-
c.session.logger.Error("unknown frame in response to options: %v", newLogFieldString("frame_type", fmt.Sprintf("%T", resp)))
121+
c.session.logger.Error("Unknown frame in response to options.", newLogFieldString("frame_type", fmt.Sprintf("%T", resp)))
122122
}
123123

124124
reconn:
@@ -246,18 +246,18 @@ func (c *controlConn) discoverProtocol(hosts []*HostInfo) (int, error) {
246246
}
247247

248248
if err == nil {
249-
c.session.logger.Debug("discovered protocol version %v using host %v (%s).",
249+
c.session.logger.Debug("Discovered protocol version using host.",
250250
newLogFieldInt("protocol_version", connCfg.ProtoVersion), newLogFieldIp("host_addr", host.ConnectAddress()), newLogFieldString("host_id", host.HostID()))
251251
return connCfg.ProtoVersion, nil
252252
}
253253

254254
if proto := parseProtocolFromError(err); proto > 0 {
255-
c.session.logger.Debug("discovered protocol version %v using host %v (%s).",
255+
c.session.logger.Debug("Discovered protocol version using host after parsing protocol error.",
256256
newLogFieldInt("protocol_version", proto), newLogFieldIp("host_addr", host.ConnectAddress()), newLogFieldString("host_id", host.HostID()))
257257
return proto, nil
258258
}
259259

260-
c.session.logger.Debug("failed to discover protocol version using host %v (%v): %v.",
260+
c.session.logger.Debug("Failed to discover protocol version using host.",
261261
newLogFieldIp("host_addr", host.ConnectAddress()), newLogFieldString("host_id", host.HostID()), newLogFieldError("err", err))
262262
}
263263

@@ -281,7 +281,7 @@ func (c *controlConn) connect(hosts []*HostInfo) error {
281281
for _, host := range hosts {
282282
conn, err = c.session.dial(c.session.ctx, host, &cfg, c)
283283
if err != nil {
284-
c.session.logger.Info("unable to dial control conn %s:%v (%s): %v",
284+
c.session.logger.Info("Control connection failed to establish a connection to host.",
285285
newLogFieldIp("host_addr", host.ConnectAddress()),
286286
newLogFieldInt("port", host.Port()),
287287
newLogFieldString("host_id", host.HostID()),
@@ -292,7 +292,7 @@ func (c *controlConn) connect(hosts []*HostInfo) error {
292292
if err == nil {
293293
break
294294
}
295-
c.session.logger.Info("unable setup control conn %v:%v (%s): %v",
295+
c.session.logger.Info("Control connection setup failed after connecting to host.",
296296
newLogFieldIp("host_addr", host.ConnectAddress()),
297297
newLogFieldInt("port", host.Port()),
298298
newLogFieldString("host_id", host.HostID()),
@@ -333,7 +333,7 @@ func (c *controlConn) setupConn(conn *Conn) error {
333333
}
334334

335335
if !exists {
336-
c.session.logger.Info("adding host %v (%v).",
336+
c.session.logger.Info("Adding host.",
337337
newLogFieldIp("host_addr", host.ConnectAddress()), newLogFieldString("host_id", host.HostID()))
338338
}
339339

@@ -348,7 +348,7 @@ func (c *controlConn) setupConn(conn *Conn) error {
348348

349349
c.conn.Store(ch)
350350

351-
c.session.logger.Info("control connection connected to %v (%s).",
351+
c.session.logger.Info("Control connection connected to host.",
352352
newLogFieldIp("host_addr", host.ConnectAddress()), newLogFieldString("host_id", host.HostID()))
353353

354354
if c.session.initialized() {
@@ -410,21 +410,21 @@ func (c *controlConn) reconnect() {
410410
_, err := c.attemptReconnect()
411411

412412
if err != nil {
413-
c.session.logger.Error("unable to reconnect control connection: %v",
413+
c.session.logger.Error("Unable to reconnect control connection.",
414414
newLogFieldError("err", err))
415415
return
416416
}
417417

418418
err = c.session.refreshRing()
419419
if err != nil {
420-
c.session.logger.Warning("unable to refresh ring: %v",
420+
c.session.logger.Warning("Unable to refresh ring.",
421421
newLogFieldError("err", err))
422422
}
423423
}
424424

425425
func (c *controlConn) attemptReconnect() (*Conn, error) {
426426

427-
c.session.logger.Info("reconnecting the control connection.")
427+
c.session.logger.Info("Reconnecting the control connection.")
428428

429429
hosts := c.session.ring.allHosts()
430430
hosts = shuffleHosts(hosts)
@@ -448,7 +448,7 @@ func (c *controlConn) attemptReconnect() (*Conn, error) {
448448
return conn, err
449449
}
450450

451-
c.session.logger.Error("unable to connect to any ring node, control connection falling back to initial contact points: %v", newLogFieldError("err", err))
451+
c.session.logger.Error("Unable to connect to any ring node, control connection falling back to initial contact points.", newLogFieldError("err", err))
452452
// Fallback to initial contact points, as it may be the case that all known initialHosts
453453
// changed their IPs while keeping the same hostname(s).
454454
initialHosts, resolvErr := addrsToHosts(c.session.cfg.Hosts, c.session.cfg.Port, c.session.logger)
@@ -465,7 +465,7 @@ func (c *controlConn) attemptReconnectToAnyOfHosts(hosts []*HostInfo) (*Conn, er
465465
for _, host := range hosts {
466466
conn, err = c.session.connect(c.session.ctx, host, c)
467467
if err != nil {
468-
c.session.logger.Info("unable to dial control conn %s:%v (%s): %v",
468+
c.session.logger.Info("During reconnection, control connection failed to establish a connection to host.",
469469
newLogFieldIp("host_addr", host.ConnectAddress()),
470470
newLogFieldInt("port", host.Port()),
471471
newLogFieldString("host_id", host.HostID()),
@@ -476,7 +476,7 @@ func (c *controlConn) attemptReconnectToAnyOfHosts(hosts []*HostInfo) (*Conn, er
476476
if err == nil {
477477
break
478478
}
479-
c.session.logger.Info("unable setup control conn %v:%v (%s): %v",
479+
c.session.logger.Info("During reconnection, control connection setup failed after connecting to host.",
480480
newLogFieldIp("host_addr", host.ConnectAddress()),
481481
newLogFieldInt("port", host.Port()),
482482
newLogFieldString("host_id", host.HostID()),
@@ -500,7 +500,7 @@ func (c *controlConn) HandleError(conn *Conn, err error, closed bool) {
500500
return
501501
}
502502

503-
c.session.logger.Info("control connection error %v (%s): %v",
503+
c.session.logger.Info("Control connection error.",
504504
newLogFieldIp("host_addr", conn.host.ConnectAddress()),
505505
newLogFieldString("host_id", conn.host.HostID()),
506506
newLogFieldError("err", err))
@@ -567,7 +567,7 @@ func (c *controlConn) query(statement string, values ...interface{}) (iter *Iter
567567
})
568568

569569
if iter.err != nil {
570-
c.session.logger.Warning("control: error executing %v: %v",
570+
c.session.logger.Warning("Error executing control connection statement.",
571571
newLogFieldString("statement", statement), newLogFieldError("err", iter.err))
572572
}
573573

events.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func (e *eventDebouncer) debounce(frame frame) {
103103
if len(e.events) < eventBufferSize {
104104
e.events = append(e.events, frame)
105105
} else {
106-
e.logger.Warning("%s: buffer full, dropping event frame: %s",
106+
e.logger.Warning("Event buffer full, dropping event frame.",
107107
newLogFieldString("event_name", e.name), newLogFieldStringer("frame", frame))
108108
}
109109

@@ -113,11 +113,11 @@ func (e *eventDebouncer) debounce(frame frame) {
113113
func (s *Session) handleEvent(framer *framer) {
114114
frame, err := framer.parseFrame()
115115
if err != nil {
116-
s.logger.Error("unable to parse event frame: %v", newLogFieldError("err", err))
116+
s.logger.Error("Unable to parse event frame.", newLogFieldError("err", err))
117117
return
118118
}
119119

120-
s.logger.Debug("handling event frame: %v", newLogFieldStringer("frame", frame))
120+
s.logger.Debug("Handling event frame.", newLogFieldStringer("frame", frame))
121121

122122
switch f := frame.(type) {
123123
case *schemaChangeKeyspace, *schemaChangeFunction,
@@ -127,7 +127,7 @@ func (s *Session) handleEvent(framer *framer) {
127127
case *topologyChangeEventFrame, *statusChangeEventFrame:
128128
s.nodeEvents.debounce(frame)
129129
default:
130-
s.logger.Error("invalid event frame (%v): %v",
130+
s.logger.Error("Invalid event frame.",
131131
newLogFieldString("frame_type", fmt.Sprintf("%T", f)), newLogFieldStringer("frame", f))
132132
}
133133
}
@@ -180,7 +180,7 @@ func (s *Session) handleNodeEvent(frames []frame) {
180180
for _, frame := range frames {
181181
switch f := frame.(type) {
182182
case *topologyChangeEventFrame:
183-
s.logger.Warning("received topology change event: %v",
183+
s.logger.Warning("Received topology change event.",
184184
newLogFieldString("frame", strings.Join([]string{f.change, "->", f.host.String(), ":", strconv.Itoa(f.port)}, "")))
185185
topologyEventReceived = true
186186
case *statusChangeEventFrame:
@@ -198,7 +198,7 @@ func (s *Session) handleNodeEvent(frames []frame) {
198198
}
199199

200200
for _, f := range sEvents {
201-
s.logger.Info("dispatching status change event: %v",
201+
s.logger.Info("Dispatching status change event.",
202202
newLogFieldString("frame", strings.Join([]string{f.change, "->", f.host.String(), ":", strconv.Itoa(f.port)}, "")))
203203

204204
// ignore events we received if they were disabled
@@ -217,7 +217,7 @@ func (s *Session) handleNodeEvent(frames []frame) {
217217
}
218218

219219
func (s *Session) handleNodeUp(eventIp net.IP, eventPort int) {
220-
s.logger.Info("node is UP: %s:%d",
220+
s.logger.Info("Node is UP.",
221221
newLogFieldStringer("event_ip", eventIp), newLogFieldInt("event_port", eventPort))
222222

223223
host, ok := s.ring.getHostByIP(eventIp.String())
@@ -243,7 +243,7 @@ func (s *Session) startPoolFill(host *HostInfo) {
243243
}
244244

245245
func (s *Session) handleNodeConnected(host *HostInfo) {
246-
s.logger.Debug("connected to node: %s:%d (%s)",
246+
s.logger.Debug("Pool connected to node.",
247247
newLogFieldIp("host_addr", host.ConnectAddress()), newLogFieldInt("port", host.Port()), newLogFieldString("host_id", host.HostID()))
248248

249249
host.setState(NodeUp)
@@ -254,7 +254,7 @@ func (s *Session) handleNodeConnected(host *HostInfo) {
254254
}
255255

256256
func (s *Session) handleNodeDown(ip net.IP, port int) {
257-
s.logger.Warning("node is DOWN: %s:%d",
257+
s.logger.Warning("Node is DOWN.",
258258
newLogFieldIp("host_addr", ip), newLogFieldInt("port", port))
259259

260260
host, ok := s.ring.getHostByIP(ip.String())

helpers.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ func getCassandraLongType(name string, protoVer byte, logger StructuredLogger) T
181181
} else if strings.HasPrefix(name, MAP_TYPE) {
182182
names := splitJavaCompositeTypes(name, MAP_TYPE)
183183
if len(names) != 2 {
184-
logger.Warning("Error parsing map type, it has %d subelements, expecting 2",
184+
logger.Warning("Error parsing map type, expected 2 subelements.",
185185
newLogFieldInt("subelements_number", len(names)))
186186
return NewNativeType(protoVer, TypeCustom)
187187
}
@@ -227,7 +227,7 @@ func getCassandraLongType(name string, protoVer byte, logger StructuredLogger) T
227227
subType := getCassandraLongType(strings.TrimSpace(names[0]), protoVer, logger)
228228
dim, err := strconv.Atoi(strings.TrimSpace(names[1]))
229229
if err != nil {
230-
logger.Warning("Error parsing vector dimensions: %v", newLogFieldError("error", err))
230+
logger.Warning("Error parsing vector dimensions.", newLogFieldError("error", err))
231231
return NewNativeType(protoVer, TypeCustom)
232232
}
233233

@@ -262,7 +262,7 @@ func getCassandraType(name string, protoVer byte, logger StructuredLogger) TypeI
262262
} else if strings.HasPrefix(name, "map<") {
263263
names := splitCQLCompositeTypes(name, "map")
264264
if len(names) != 2 {
265-
logger.Warning("Error parsing map type, it has %d subelements, expecting 2",
265+
logger.Warning("Error parsing map type, expected 2 subelements.",
266266
newLogFieldInt("subelements_number", len(names)))
267267
return NewNativeType(protoVer, TypeCustom)
268268
}

0 commit comments

Comments
 (0)