Skip to content

Commit

Permalink
feat(spanner): configurable logger (#6958)
Browse files Browse the repository at this point in the history
Expose logger in ClientConfig so consumers can set a logger.

This is useful when using spannertest which logs a lot of harmless
errors.

Fixes: #6957

Co-authored-by: rahul2393 <irahul@google.com>
  • Loading branch information
stevenh and rahul2393 authored Nov 3, 2022
1 parent d5e2e0f commit bd85442
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions spanner/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ type ClientConfig struct {
// Recommended format: ``application-or-tool-ID/major.minor.version``.
UserAgent string

// logger is the logger to use for this client. If it is nil, all logging
// Logger is the logger to use for this client. If it is nil, all logging
// will be directed to the standard logger.
logger *log.Logger
Logger *log.Logger
}

func contextWithOutgoingMetadata(ctx context.Context, md metadata.MD) context.Context {
Expand Down Expand Up @@ -220,7 +220,7 @@ func NewClientWithConfig(ctx context.Context, database string, config ClientConf
config.incStep = DefaultSessionPoolConfig.incStep
}
// Create a session client.
sc := newSessionClient(pool, database, config.UserAgent, sessionLabels, metadata.Pairs(resourcePrefixHeader, database), config.logger, config.CallOptions)
sc := newSessionClient(pool, database, config.UserAgent, sessionLabels, metadata.Pairs(resourcePrefixHeader, database), config.Logger, config.CallOptions)
// Create a session pool.
config.SessionPoolConfig.sessionLabels = sessionLabels
sp, err := newSessionPool(sc, config.SessionPoolConfig)
Expand All @@ -231,7 +231,7 @@ func NewClientWithConfig(ctx context.Context, database string, config ClientConf
c = &Client{
sc: sc,
idleSessions: sp,
logger: config.logger,
logger: config.Logger,
qo: getQueryOptions(config.QueryOptions),
ro: config.ReadOptions,
ao: config.ApplyOptions,
Expand Down
2 changes: 1 addition & 1 deletion spanner/pdml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func TestPartitionedUpdate_WithDeadline(t *testing.T) {
logger := log.New(os.Stderr, "", log.LstdFlags)
server, client, teardown := setupMockedTestServerWithConfig(t, ClientConfig{
SessionPoolConfig: DefaultSessionPoolConfig,
logger: logger,
Logger: logger,
})
defer teardown()

Expand Down
4 changes: 2 additions & 2 deletions spanner/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1122,7 +1122,7 @@ func TestErrorOnPrepareSession(t *testing.T) {
WriteSessions: 0.5,
HealthCheckInterval: time.Millisecond,
},
logger: logger,
Logger: logger,
})
defer teardown()
// Discard logging until trying to prepare sessions has stopped.
Expand Down Expand Up @@ -1244,7 +1244,7 @@ func TestSessionNotFoundOnPrepareSession(t *testing.T) {
HealthCheckInterval: time.Millisecond,
healthCheckSampleInterval: time.Millisecond,
},
logger: logger,
Logger: logger,
})
defer teardown()
// Discard logging until trying to prepare sessions has stopped.
Expand Down

0 comments on commit bd85442

Please sign in to comment.