Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #15

Merged
merged 2 commits into from
Feb 9, 2024
Merged

Dev #15

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions httpclient/httpclient_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ type AuthConfig struct {

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

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

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

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

// Use the APIType from the config to determine which API handler to load
apiHandler, err := LoadAPIHandler(config.Environment.APIType, log)
Expand Down Expand Up @@ -165,7 +164,7 @@ func BuildClient(config ClientConfig) (*Client, error) {
zap.String("Instance Name", client.InstanceName),
zap.String("Override Base Domain", config.Environment.OverrideBaseDomain),
zap.String("Authentication Method", authMethod),
zap.String("Logging Level", config.ClientOptions.LogLevel.String()),
zap.String("Logging Level", config.ClientOptions.LogLevel),
zap.Bool("Hide Sensitive Data In Logs", config.ClientOptions.HideSensitiveData),
zap.Int("Max Retry Attempts", config.ClientOptions.MaxRetryAttempts),
zap.Int("Max Concurrent Requests", config.ClientOptions.MaxConcurrentRequests),
Expand Down
37 changes: 19 additions & 18 deletions logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,26 @@ const (
LogLevelNone
)

// String returns the string representation of the LogLevel.
func (l LogLevel) String() string {
switch l {
case LogLevelDebug:
return "LogLevelDebug"
case LogLevelInfo:
return "LogLevelInfo"
case LogLevelWarn:
return "LogLevelWarn"
case LogLevelError:
return "LogLevelError"
case LogLevelDPanic:
return "LogLevelDPanic"
case LogLevelPanic:
return "LogLevelPanic"
case LogLevelFatal:
return "LogLevelFatal"
// ParseLogLevelFromString takes a string representation of the log level and returns the corresponding LogLevel.
// Used to convert a string log level from a configuration file to a strongly-typed LogLevel.
func ParseLogLevelFromString(levelStr string) LogLevel {
switch levelStr {
case "LogLevelDebug":
return LogLevelDebug
case "LogLevelInfo":
return LogLevelInfo
case "LogLevelWarn":
return LogLevelWarn
case "LogLevelError":
return LogLevelError
case "LogLevelDPanic":
return LogLevelDPanic
case "LogLevelPanic":
return LogLevelPanic
case "LogLevelFatal":
return LogLevelFatal
default:
return "Unknown"
return LogLevelNone
}
}

Expand Down