Skip to content

Commit 4cd3a9c

Browse files
authored
Merge pull request #15 from deploymenttheory/dev
Dev
2 parents b51e09a + fa061ec commit 4cd3a9c

File tree

2 files changed

+31
-31
lines changed

2 files changed

+31
-31
lines changed

httpclient/httpclient_client.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ type AuthConfig struct {
5858

5959
// ClientOptions holds optional configuration options for the HTTP Client.
6060
type ClientOptions struct {
61-
LogLevel logger.LogLevel // Field for defining tiered logging level.
62-
HideSensitiveData bool // Field for defining whether sensitive fields should be hidden in logs.
63-
MaxRetryAttempts int // Config item defines the max number of retry request attempts for retryable HTTP methods.
64-
EnableDynamicRateLimiting bool // Field for defining whether dynamic rate limiting should be enabled.
65-
MaxConcurrentRequests int // Field for defining the maximum number of concurrent requests allowed in the semaphore
61+
LogLevel string // Field for defining tiered logging level.
62+
HideSensitiveData bool // Field for defining whether sensitive fields should be hidden in logs.
63+
MaxRetryAttempts int // Config item defines the max number of retry request attempts for retryable HTTP methods.
64+
EnableDynamicRateLimiting bool // Field for defining whether dynamic rate limiting should be enabled.
65+
MaxConcurrentRequests int // Field for defining the maximum number of concurrent requests allowed in the semaphore
6666
TokenRefreshBufferPeriod time.Duration
6767
TotalRetryDuration time.Duration
6868
CustomTimeout time.Duration
@@ -81,15 +81,14 @@ type PerformanceMetrics struct {
8181

8282
// BuildClient creates a new HTTP client with the provided configuration.
8383
func BuildClient(config ClientConfig) (*Client, error) {
84-
// Initialize the zap logger.
85-
log := logger.BuildLogger(config.ClientOptions.LogLevel)
84+
// Parse the log level string to logger.LogLevel
85+
parsedLogLevel := logger.ParseLogLevelFromString(config.ClientOptions.LogLevel)
8686

87-
// Set the logger's level based on the provided configuration.
88-
log.SetLevel(config.ClientOptions.LogLevel)
87+
// Initialize the logger with the parsed log level
88+
log := logger.BuildLogger(parsedLogLevel)
8989

90-
if config.ClientOptions.LogLevel < logger.LogLevelDebug || config.ClientOptions.LogLevel > logger.LogLevelFatal {
91-
return nil, log.Error("Invalid LogLevel setting", zap.Int("Provided LogLevel", int(config.ClientOptions.LogLevel)))
92-
}
90+
// Set the logger's level (optional if BuildLogger already sets the level based on the input)
91+
log.SetLevel(parsedLogLevel)
9392

9493
// Use the APIType from the config to determine which API handler to load
9594
apiHandler, err := LoadAPIHandler(config.Environment.APIType, log)
@@ -165,7 +164,7 @@ func BuildClient(config ClientConfig) (*Client, error) {
165164
zap.String("Instance Name", client.InstanceName),
166165
zap.String("Override Base Domain", config.Environment.OverrideBaseDomain),
167166
zap.String("Authentication Method", authMethod),
168-
zap.String("Logging Level", config.ClientOptions.LogLevel.String()),
167+
zap.String("Logging Level", config.ClientOptions.LogLevel),
169168
zap.Bool("Hide Sensitive Data In Logs", config.ClientOptions.HideSensitiveData),
170169
zap.Int("Max Retry Attempts", config.ClientOptions.MaxRetryAttempts),
171170
zap.Int("Max Concurrent Requests", config.ClientOptions.MaxConcurrentRequests),

logger/logger.go

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,26 @@ const (
3131
LogLevelNone
3232
)
3333

34-
// String returns the string representation of the LogLevel.
35-
func (l LogLevel) String() string {
36-
switch l {
37-
case LogLevelDebug:
38-
return "LogLevelDebug"
39-
case LogLevelInfo:
40-
return "LogLevelInfo"
41-
case LogLevelWarn:
42-
return "LogLevelWarn"
43-
case LogLevelError:
44-
return "LogLevelError"
45-
case LogLevelDPanic:
46-
return "LogLevelDPanic"
47-
case LogLevelPanic:
48-
return "LogLevelPanic"
49-
case LogLevelFatal:
50-
return "LogLevelFatal"
34+
// ParseLogLevelFromString takes a string representation of the log level and returns the corresponding LogLevel.
35+
// Used to convert a string log level from a configuration file to a strongly-typed LogLevel.
36+
func ParseLogLevelFromString(levelStr string) LogLevel {
37+
switch levelStr {
38+
case "LogLevelDebug":
39+
return LogLevelDebug
40+
case "LogLevelInfo":
41+
return LogLevelInfo
42+
case "LogLevelWarn":
43+
return LogLevelWarn
44+
case "LogLevelError":
45+
return LogLevelError
46+
case "LogLevelDPanic":
47+
return LogLevelDPanic
48+
case "LogLevelPanic":
49+
return LogLevelPanic
50+
case "LogLevelFatal":
51+
return LogLevelFatal
5152
default:
52-
return "Unknown"
53+
return LogLevelNone
5354
}
5455
}
5556

0 commit comments

Comments
 (0)