Skip to content

Commit 4f1573b

Browse files
committed
remove legacy logger
1 parent 6b45c42 commit 4f1573b

33 files changed

+318
-206
lines changed

address_translators_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//go:build all || unit
2+
// +build all unit
3+
14
/*
25
* Licensed to the Apache Software Foundation (ASF) under one
36
* or more contributor license agreements. See the NOTICE file

cluster.go

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -259,33 +259,17 @@ type ClusterConfig struct {
259259
// If not provided, Dialer will be used instead.
260260
HostDialer HostDialer
261261

262-
// Deprecated: use StructuredLogger instead, Logger and LegacyLogLevel will be removed in the future.
263-
//
264-
// Logger for this ClusterConfig.
265-
// If not specified, defaults to the gocql.defaultLogger.
266-
Logger StdLogger
267-
268262
// StructuredLogger for this ClusterConfig.
269-
// If not specified, Logger will be used instead (note that Logger is deprecated).
270263
//
271-
// There are 3 built in implementations of StructuredLogger:
264+
// You can change the log level of the default logger by creating a new logger using gocql.NewLogger and providing it here.
265+
//
266+
//There are 3 built in implementations of StructuredLogger:
272267
// - std library "log" package: gocql.NewLogger
273268
// - zerolog: gocqlzerolog.NewZerologLogger
274269
// - zap: gocqlzap.NewZapLogger
275270
//
276-
// The logger created by gocql.NewLogger behaves in a similar way as the legacy default logger, but you can set a log level.
277-
//
278271
// You can also provide your own logger implementation of the StructuredLogger interface.
279-
StructuredLogger StructuredLogger
280-
281-
// Deprecated: use StructuredLogger instead, Logger and LegacyLogLevel will be removed in the future.
282-
//
283-
// LegacyLogLevel for this ClusterConfig, this is only applied for legacy loggers (field Logger).
284-
// This log level is not applied to StructuredLogger because the log level is already a part of the interface
285-
// so the implementation can decide when not to log something.
286-
//
287-
// If not specified, LogLevelNone will be used as the default.
288-
LegacyLogLevel LogLevel
272+
Logger StructuredLogger
289273

290274
// Tracer will be used for all queries. Alternatively it can be set of on a
291275
// per query basis.
@@ -333,20 +317,16 @@ func NewCluster(hosts ...string) *ClusterConfig {
333317
ConvictionPolicy: &SimpleConvictionPolicy{},
334318
ReconnectionPolicy: &ConstantReconnectionPolicy{MaxRetries: 3, Interval: 1 * time.Second},
335319
WriteCoalesceWaitTime: 200 * time.Microsecond,
336-
LegacyLogLevel: LogLevelNone,
337320
NextPagePrefetch: 0.25,
338321
}
339322
return cfg
340323
}
341324

342-
func (cfg *ClusterConfig) newLogger() loggerAdapter {
343-
if cfg.StructuredLogger != nil {
344-
return newInternalLoggerFromAdvancedLogger(cfg.StructuredLogger)
345-
}
346-
if cfg.Logger == nil {
347-
return newInternalLoggerFromStdLogger(&defaultLogger{}, cfg.LegacyLogLevel)
325+
func (cfg *ClusterConfig) newLogger() StructuredLogger {
326+
if cfg.Logger != nil {
327+
return cfg.Logger
348328
}
349-
return newInternalLoggerFromStdLogger(cfg.Logger, cfg.LegacyLogLevel)
329+
return NewLogger(LogLevelNone)
350330
}
351331

352332
// CreateSession initializes the cluster based on this config and returns a
@@ -359,7 +339,7 @@ func (cfg *ClusterConfig) CreateSession() (*Session, error) {
359339
// if defined, to translate the given address and port into a possibly new address
360340
// and port, If no AddressTranslator or if an error occurs, the given address and
361341
// port will be returned.
362-
func (cfg *ClusterConfig) translateAddressPort(addr net.IP, port int, logger internalLogger) (net.IP, int) {
342+
func (cfg *ClusterConfig) translateAddressPort(addr net.IP, port int, logger StructuredLogger) (net.IP, int) {
363343
if cfg.AddressTranslator == nil || len(addr) == 0 {
364344
return addr, port
365345
}

cluster_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//go:build all || unit
2+
// +build all unit
3+
14
/*
25
* Licensed to the Apache Software Foundation (ASF) under one
36
* or more contributor license agreements. See the NOTICE file
@@ -60,23 +63,23 @@ func TestNewCluster_WithHosts(t *testing.T) {
6063
func TestClusterConfig_translateAddressAndPort_NilTranslator(t *testing.T) {
6164
cfg := NewCluster()
6265
assertNil(t, "cluster config address translator", cfg.AddressTranslator)
63-
newAddr, newPort := cfg.translateAddressPort(net.ParseIP("10.0.0.1"), 1234, nilInternalLogger)
66+
newAddr, newPort := cfg.translateAddressPort(net.ParseIP("10.0.0.1"), 1234, nopLoggerSingleton)
6467
assertTrue(t, "same address as provided", net.ParseIP("10.0.0.1").Equal(newAddr))
6568
assertEqual(t, "translated host and port", 1234, newPort)
6669
}
6770

6871
func TestClusterConfig_translateAddressAndPort_EmptyAddr(t *testing.T) {
6972
cfg := NewCluster()
7073
cfg.AddressTranslator = staticAddressTranslator(net.ParseIP("10.10.10.10"), 5432)
71-
newAddr, newPort := cfg.translateAddressPort(net.IP([]byte{}), 0, nilInternalLogger)
74+
newAddr, newPort := cfg.translateAddressPort(net.IP([]byte{}), 0, nopLoggerSingleton)
7275
assertTrue(t, "translated address is still empty", len(newAddr) == 0)
7376
assertEqual(t, "translated port", 0, newPort)
7477
}
7578

7679
func TestClusterConfig_translateAddressAndPort_Success(t *testing.T) {
7780
cfg := NewCluster()
7881
cfg.AddressTranslator = staticAddressTranslator(net.ParseIP("10.10.10.10"), 5432)
79-
newAddr, newPort := cfg.translateAddressPort(net.ParseIP("10.0.0.1"), 2345, nilInternalLogger)
82+
newAddr, newPort := cfg.translateAddressPort(net.ParseIP("10.0.0.1"), 2345, nopLoggerSingleton)
8083
assertTrue(t, "translated address", net.ParseIP("10.10.10.10").Equal(newAddr))
8184
assertEqual(t, "translated port", 5432, newPort)
8285
}

common_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//go:build all || unit
2+
// +build all unit
3+
14
/*
25
* Licensed to the Apache Software Foundation (ASF) under one
36
* or more contributor license agreements. See the NOTICE file

compressor_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//go:build all || unit
2+
// +build all unit
3+
14
/*
25
* Licensed to the Apache Software Foundation (ASF) under one
36
* or more contributor license agreements. See the NOTICE file

conn.go

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -133,20 +133,18 @@ type SslOptions struct {
133133
}
134134

135135
type ConnConfig struct {
136-
ProtoVersion int
137-
CQLVersion string
138-
Timeout time.Duration
139-
WriteTimeout time.Duration
140-
ConnectTimeout time.Duration
141-
Dialer Dialer
142-
HostDialer HostDialer
143-
Compressor Compressor
144-
Authenticator Authenticator
145-
AuthProvider func(h *HostInfo) (Authenticator, error)
146-
Keepalive time.Duration
147-
Logger StdLogger
148-
StructuredLogger StructuredLogger
149-
LegacyLogLevel LogLevel
136+
ProtoVersion int
137+
CQLVersion string
138+
Timeout time.Duration
139+
WriteTimeout time.Duration
140+
ConnectTimeout time.Duration
141+
Dialer Dialer
142+
HostDialer HostDialer
143+
Compressor Compressor
144+
Authenticator Authenticator
145+
AuthProvider func(h *HostInfo) (Authenticator, error)
146+
Keepalive time.Duration
147+
Logger StructuredLogger
150148

151149
tlsConfig *tls.Config
152150
disableCoalesce bool
@@ -203,7 +201,7 @@ type Conn struct {
203201

204202
timeouts int64
205203

206-
logger internalLogger
204+
logger StructuredLogger
207205
}
208206

209207
// connect establishes a connection to a Cassandra node using session's connection config.

conn_test.go

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import (
4141
"math/rand"
4242
"net"
4343
"os"
44+
"strconv"
4445
"strings"
4546
"sync"
4647
"sync/atomic"
@@ -184,7 +185,7 @@ func newTestSession(proto protoVersion, addresses ...string) (*Session, error) {
184185
}
185186

186187
func TestDNSLookupConnected(t *testing.T) {
187-
log := &testLogger{}
188+
log := newTestLogger(LogLevelDebug)
188189

189190
// Override the defaul DNS resolver and restore at the end
190191
failDNS = true
@@ -195,7 +196,6 @@ func TestDNSLookupConnected(t *testing.T) {
195196

196197
cluster := NewCluster("cassandra1.invalid", srv.Address, "cassandra2.invalid")
197198
cluster.Logger = log
198-
cluster.LegacyLogLevel = LogLevelDebug
199199
cluster.ProtoVersion = int(defaultProto)
200200
cluster.disableControlConn = true
201201

@@ -212,15 +212,14 @@ func TestDNSLookupConnected(t *testing.T) {
212212
}
213213

214214
func TestDNSLookupError(t *testing.T) {
215-
log := &testLogger{}
215+
log := newTestLogger(LogLevelDebug)
216216

217217
// Override the defaul DNS resolver and restore at the end
218218
failDNS = true
219219
defer func() { failDNS = false }()
220220

221221
cluster := NewCluster("cassandra1.invalid", "cassandra2.invalid")
222222
cluster.Logger = log
223-
cluster.LegacyLogLevel = LogLevelDebug
224223
cluster.ProtoVersion = int(defaultProto)
225224
cluster.disableControlConn = true
226225

@@ -242,7 +241,7 @@ func TestDNSLookupError(t *testing.T) {
242241

243242
func TestStartupTimeout(t *testing.T) {
244243
ctx, cancel := context.WithCancel(context.Background())
245-
log := &testLogger{}
244+
log := newTestLogger(LogLevelDebug)
246245

247246
srv := NewTestServer(t, defaultProto, ctx)
248247
defer srv.Stop()
@@ -253,7 +252,6 @@ func TestStartupTimeout(t *testing.T) {
253252
startTime := time.Now()
254253
cluster := NewCluster(srv.Address)
255254
cluster.Logger = log
256-
cluster.LegacyLogLevel = LogLevelDebug
257255
cluster.ProtoVersion = int(defaultProto)
258256
cluster.disableControlConn = true
259257
// Set very long query connection timeout
@@ -352,15 +350,21 @@ func TestCancel(t *testing.T) {
352350
type testQueryObserver struct {
353351
metrics map[string]*hostMetrics
354352
verbose bool
355-
logger StdLogger
353+
logger StructuredLogger
356354
}
357355

358356
func (o *testQueryObserver) ObserveQuery(ctx context.Context, q ObservedQuery) {
359357
host := q.Host.ConnectAddress().String()
360358
o.metrics[host] = q.Metrics
361359
if o.verbose {
362-
o.logger.Printf("Observed query %q. Returned %v rows, took %v on host %q with %v attempts and total latency %v. Error: %q\n",
363-
q.Statement, q.Rows, q.End.Sub(q.Start), host, q.Metrics.Attempts, q.Metrics.TotalLatency, q.Err)
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",
361+
newLogFieldString("stmt", q.Statement),
362+
newLogFieldInt("rows", q.Rows),
363+
newLogFieldString("duration", q.End.Sub(q.Start).String()),
364+
newLogFieldString("host", host),
365+
newLogFieldInt("attempts", q.Metrics.Attempts),
366+
newLogFieldString("latency", strconv.FormatInt(q.Metrics.TotalLatency, 10)),
367+
newLogFieldError("err", q.Err))
364368
}
365369
}
366370

@@ -412,7 +416,7 @@ func TestQueryRetry(t *testing.T) {
412416
}
413417

414418
func TestQueryMultinodeWithMetrics(t *testing.T) {
415-
log := &testLogger{}
419+
log := newTestLogger(LogLevelDebug)
416420
defer func() {
417421
os.Stdout.WriteString(log.String())
418422
}()
@@ -487,7 +491,7 @@ func (t *testRetryPolicy) GetRetryType(err error) RetryType {
487491
}
488492

489493
func TestSpeculativeExecution(t *testing.T) {
490-
log := &testLogger{}
494+
log := newTestLogger(LogLevelDebug)
491495
defer func() {
492496
os.Stdout.WriteString(log.String())
493497
}()
@@ -720,7 +724,7 @@ func TestStream0(t *testing.T) {
720724
r: bufio.NewReader(&buf),
721725
},
722726
streams: streams.New(protoVersion4),
723-
logger: newInternalLoggerFromStdLogger(&defaultLogger{}, LogLevelNone),
727+
logger: &defaultLogger{},
724728
}
725729

726730
err := conn.recv(context.Background(), false)

connectionpool.go

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -143,20 +143,18 @@ func connConfig(cfg *ClusterConfig) (*ConnConfig, error) {
143143
}
144144

145145
return &ConnConfig{
146-
ProtoVersion: cfg.ProtoVersion,
147-
CQLVersion: cfg.CQLVersion,
148-
Timeout: cfg.Timeout,
149-
WriteTimeout: cfg.WriteTimeout,
150-
ConnectTimeout: cfg.ConnectTimeout,
151-
Dialer: cfg.Dialer,
152-
HostDialer: hostDialer,
153-
Compressor: cfg.Compressor,
154-
Authenticator: cfg.Authenticator,
155-
AuthProvider: cfg.AuthProvider,
156-
Keepalive: cfg.SocketKeepalive,
157-
Logger: cfg.Logger,
158-
StructuredLogger: cfg.StructuredLogger,
159-
LegacyLogLevel: cfg.LegacyLogLevel,
146+
ProtoVersion: cfg.ProtoVersion,
147+
CQLVersion: cfg.CQLVersion,
148+
Timeout: cfg.Timeout,
149+
WriteTimeout: cfg.WriteTimeout,
150+
ConnectTimeout: cfg.ConnectTimeout,
151+
Dialer: cfg.Dialer,
152+
HostDialer: hostDialer,
153+
Compressor: cfg.Compressor,
154+
Authenticator: cfg.Authenticator,
155+
AuthProvider: cfg.AuthProvider,
156+
Keepalive: cfg.SocketKeepalive,
157+
Logger: cfg.Logger,
160158
}, nil
161159
}
162160

@@ -312,7 +310,7 @@ type hostConnPool struct {
312310
filling bool
313311

314312
pos uint32
315-
logger internalLogger
313+
logger StructuredLogger
316314
}
317315

318316
func (h *hostConnPool) String() string {

control_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//go:build all || unit
2+
// +build all unit
3+
14
/*
25
* Licensed to the Apache Software Foundation (ASF) under one
36
* or more contributor license agreements. See the NOTICE file

crc_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//go:build all || unit
2+
// +build all unit
3+
14
/*
25
* Licensed to the Apache Software Foundation (ASF) under one
36
* or more contributor license agreements. See the NOTICE file

0 commit comments

Comments
 (0)