Skip to content

Commit eed8c8c

Browse files
authored
Merge pull request #146 from deploymenttheory/dev
Added log export path to http client zap logger instance to support troubleshooting
2 parents 429c96f + 462c31b commit eed8c8c

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/google/uuid v1.6.0
88
github.com/stretchr/testify v1.9.0
99
go.uber.org/zap v1.27.0
10-
golang.org/x/net v0.22.0
10+
golang.org/x/net v0.24.0
1111
)
1212

1313
require (
@@ -17,7 +17,7 @@ require (
1717
github.com/pmezard/go-difflib v1.0.0 // indirect
1818
github.com/stretchr/objx v0.5.2 // indirect
1919
go.uber.org/multierr v1.10.0 // indirect
20-
golang.org/x/sys v0.18.0 // indirect
20+
golang.org/x/sys v0.19.0 // indirect
2121
golang.org/x/text v0.14.0 // indirect
2222
gopkg.in/yaml.v3 v3.0.1 // indirect
2323
)

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL
2828
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
2929
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
3030
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
31-
golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc=
32-
golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
31+
golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w=
32+
golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8=
3333
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
3434
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
3535
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@@ -38,8 +38,8 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
3838
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
3939
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
4040
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
41-
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
42-
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
41+
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
42+
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
4343
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
4444
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
4545
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=

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)