Skip to content

Commit

Permalink
feat: tweaks to how we configure logging (#257)
Browse files Browse the repository at this point in the history
* feat: tweaks to how we configure logging

This changes the signatures that we use to configure logging
for the client.  Prior to this commit the constructors were
taking a vararg array of loggerFactories, which might lead
users to think they could pass more than one.

This commit adds alternate constructors that accept a single
logger factory instead.
  • Loading branch information
cprice404 committed Mar 14, 2023
1 parent ef6d66c commit 7849dea
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 14 deletions.
28 changes: 14 additions & 14 deletions config/configurations.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,34 @@ import (
"github.com/momentohq/client-sdk-go/config/logger"
)

func LaptopLatest(loggerFactory ...logger.MomentoLoggerFactory) Configuration {
defaultLoggerFactory := logger.NewNoopMomentoLoggerFactory()
if len(loggerFactory) != 0 {
defaultLoggerFactory = loggerFactory[0]
}
func LaptopLatest() Configuration {
return LaptopLatestWithLogger(logger.NewNoopMomentoLoggerFactory())
}

func LaptopLatestWithLogger(loggerFactory logger.MomentoLoggerFactory) Configuration {
return NewCacheConfiguration(&ConfigurationProps{
LoggerFactory: defaultLoggerFactory,
LoggerFactory: loggerFactory,
TransportStrategy: NewStaticTransportStrategy(&TransportStrategyProps{
GrpcConfiguration: NewStaticGrpcConfiguration(&GrpcConfigurationProps{
deadline: 5 * time.Second,
}),
}),
RetryStrategy: retry.NewFixedCountRetryStrategy(defaultLoggerFactory),
RetryStrategy: retry.NewFixedCountRetryStrategy(loggerFactory),
})
}

func InRegionLatest(loggerFactory ...logger.MomentoLoggerFactory) Configuration {
defaultLoggerFactory := logger.NewNoopMomentoLoggerFactory()
if len(loggerFactory) != 0 {
defaultLoggerFactory = loggerFactory[0]
}
func InRegionLatest() Configuration {
return InRegionLatestWithLogger(logger.NewNoopMomentoLoggerFactory())
}

func InRegionLatestWithLogger(loggerFactory logger.MomentoLoggerFactory) Configuration {
return NewCacheConfiguration(&ConfigurationProps{
LoggerFactory: defaultLoggerFactory,
LoggerFactory: loggerFactory,
TransportStrategy: NewStaticTransportStrategy(&TransportStrategyProps{
GrpcConfiguration: NewStaticGrpcConfiguration(&GrpcConfigurationProps{
deadline: 1100 * time.Millisecond,
}),
}),
RetryStrategy: retry.NewFixedCountRetryStrategy(defaultLoggerFactory),
RetryStrategy: retry.NewFixedCountRetryStrategy(loggerFactory),
})
}
24 changes: 24 additions & 0 deletions momento/cache_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"errors"
"time"

"github.com/momentohq/client-sdk-go/config/logger"

"github.com/momentohq/client-sdk-go/config"
. "github.com/momentohq/client-sdk-go/momento"
. "github.com/momentohq/client-sdk-go/momento/test_helpers"
Expand Down Expand Up @@ -38,4 +40,26 @@ var _ = Describe("CacheClient", func() {
NewCacheClient(sharedContext.Configuration, sharedContext.CredentialProvider, sharedContext.DefaultTtl),
).Error().To(HaveMomentoErrorCode(InvalidArgumentError))
})

It(`Supports constructing a laptop config with a logger`, func() {
_, err := NewCacheClient(
config.LaptopLatestWithLogger(logger.NewBuiltinMomentoLoggerFactory()),
sharedContext.CredentialProvider,
sharedContext.DefaultTtl,
)
if err != nil {
panic(err)
}
})

It(`Supports constructing an InRegion config with a logger`, func() {
_, err := NewCacheClient(
config.InRegionLatestWithLogger(logger.NewBuiltinMomentoLoggerFactory()),
sharedContext.CredentialProvider,
sharedContext.DefaultTtl,
)
if err != nil {
panic(err)
}
})
})

0 comments on commit 7849dea

Please sign in to comment.