Skip to content

Commit 462c31b

Browse files
committed
Add LogExportPath field to ClientOptions struct and update logger.BuildLogger function
1 parent c14d11e commit 462c31b

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

httpclient/client.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ type ClientOptions struct {
6363
LogLevel string // Field for defining tiered logging level.
6464
LogOutputFormat string // Field for defining the output format of the logs. Use "JSON" for JSON format, "console" for human-readable format
6565
LogConsoleSeparator string // Field for defining the separator in console output format.
66+
LogExportPath string // Field for specifying the path to output logs to.
6667
HideSensitiveData bool // Field for defining whether sensitive fields should be hidden in logs.
6768
MaxRetryAttempts int // Config item defines the max number of retry request attempts for retryable HTTP methods.
6869
EnableDynamicRateLimiting bool // Field for defining whether dynamic rate limiting should be enabled.
@@ -81,7 +82,7 @@ func BuildClient(config ClientConfig) (*Client, error) {
8182
parsedLogLevel := logger.ParseLogLevelFromString(config.ClientOptions.LogLevel)
8283

8384
// Initialize the logger with parsed config values
84-
log := logger.BuildLogger(parsedLogLevel, config.ClientOptions.LogOutputFormat, config.ClientOptions.LogConsoleSeparator)
85+
log := logger.BuildLogger(parsedLogLevel, config.ClientOptions.LogOutputFormat, config.ClientOptions.LogConsoleSeparator, config.ClientOptions.LogExportPath)
8586

8687
// Set the logger's level (optional if BuildLogger already sets the level based on the input)
8788
log.SetLevel(parsedLogLevel)

logger/zaplogger_config.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
// BuildLogger creates and returns a new zap logger instance.
1212
// It configures the logger with JSON formatting and a custom encoder to ensure the 'pid', 'application', and 'timestamp' fields
1313
// appear at the end of each log message. The function panics if the logger cannot be initialized.
14-
func BuildLogger(logLevel LogLevel, encoding string, logConsoleSeparator string) Logger {
14+
func BuildLogger(logLevel LogLevel, encoding string, logConsoleSeparator string, logExportPath string) Logger {
1515
// Set default encoding to console if not provided
1616
if encoding == "" {
1717
encoding = "console"
@@ -66,6 +66,12 @@ func BuildLogger(logLevel LogLevel, encoding string, logConsoleSeparator string)
6666
//"application": version.GetAppName(),
6767
},
6868
}
69+
70+
// Conditionally set the OutputPaths to include the log export path if provided
71+
if logExportPath != "" {
72+
config.OutputPaths = append(config.OutputPaths, logExportPath)
73+
}
74+
6975
// Build the logger from the configuration
7076
logger := zap.Must(config.Build())
7177

0 commit comments

Comments
 (0)