Skip to content

Commit 3b157f7

Browse files
authored
fix: Properly use templated version of logging calls (#60)
1 parent def35fe commit 3b157f7

File tree

6 files changed

+41
-14
lines changed

6 files changed

+41
-14
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ eppoclient/test-data
1919

2020
.DS_Store
2121
memprofile*
22+
.idea/
23+
pkg/

eppoclient/applicationlogger/interface.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ package applicationlogger
33
type Logger interface {
44
Debug(args ...interface{})
55
Info(args ...interface{})
6+
Infof(template string, args ...interface{})
67
Warn(args ...interface{})
8+
Warnf(template string, args ...interface{})
79
Error(args ...interface{})
10+
Errorf(template string, args ...interface{})
811
}

eppoclient/applicationlogger/scrubbing_logger.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,22 @@ func (s *ScrubbingLogger) Info(args ...interface{}) {
4444
s.innerLogger.Info(s.scrub(args...)...)
4545
}
4646

47+
func (s *ScrubbingLogger) Infof(template string, args ...interface{}) {
48+
s.innerLogger.Infof(maskSensitiveInfo(template), s.scrub(args...)...)
49+
}
50+
4751
func (s *ScrubbingLogger) Warn(args ...interface{}) {
4852
s.innerLogger.Warn(s.scrub(args...)...)
4953
}
5054

55+
func (s *ScrubbingLogger) Warnf(template string, args ...interface{}) {
56+
s.innerLogger.Warnf(maskSensitiveInfo(template), s.scrub(args...)...)
57+
}
58+
5159
func (s *ScrubbingLogger) Error(args ...interface{}) {
5260
s.innerLogger.Error(s.scrub(args...)...)
5361
}
62+
63+
func (s *ScrubbingLogger) Errorf(template string, args ...interface{}) {
64+
s.innerLogger.Errorf(maskSensitiveInfo(template), s.scrub(args...)...)
65+
}

eppoclient/applicationlogger/zap_logger.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import (
44
"go.uber.org/zap"
55
)
66

7-
/**
8-
* The default logger for the SDK.
9-
*/
7+
// ZapLogger The default logger for the Eppo SDK
108
type ZapLogger struct {
119
logger *zap.Logger
1210
}
@@ -23,10 +21,22 @@ func (z *ZapLogger) Info(args ...interface{}) {
2321
z.logger.Sugar().Info(args...)
2422
}
2523

24+
func (z *ZapLogger) Infof(template string, args ...interface{}) {
25+
z.logger.Sugar().Infof(template, args...)
26+
}
27+
2628
func (z *ZapLogger) Warn(args ...interface{}) {
2729
z.logger.Sugar().Warn(args...)
2830
}
2931

32+
func (z *ZapLogger) Warnf(template string, args ...interface{}) {
33+
z.logger.Sugar().Warnf(template, args...)
34+
}
35+
3036
func (z *ZapLogger) Error(args ...interface{}) {
3137
z.logger.Sugar().Error(args...)
3238
}
39+
40+
func (z *ZapLogger) Errorf(template string, args ...interface{}) {
41+
z.logger.Sugar().Errorf(template, args...)
42+
}

eppoclient/client.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
type Attributes map[string]interface{}
1111

12-
// Client for eppo.cloud. Instance of this struct will be created on calling InitClient.
12+
// EppoClient Client for eppo.cloud. Instance of this struct will be created on calling InitClient.
1313
// EppoClient will then immediately start polling experiments data from Eppo.
1414
type EppoClient struct {
1515
configurationStore *configurationStore
@@ -42,7 +42,7 @@ func (ec *EppoClient) GetBoolAssignment(flagKey string, subjectKey string, subje
4242
}
4343
result, ok := variation.(bool)
4444
if !ok {
45-
ec.applicationLogger.Error("failed to cast %v to bool", variation)
45+
ec.applicationLogger.Errorf("failed to cast %v to bool", variation)
4646
return defaultValue, fmt.Errorf("failed to cast %v to bool", variation)
4747
}
4848
return result, err
@@ -55,7 +55,7 @@ func (ec *EppoClient) GetNumericAssignment(flagKey string, subjectKey string, su
5555
}
5656
result, ok := variation.(float64)
5757
if !ok {
58-
ec.applicationLogger.Error("failed to cast %v to float64", variation)
58+
ec.applicationLogger.Errorf("failed to cast %v to float64", variation)
5959
return defaultValue, fmt.Errorf("failed to cast %v to float64", variation)
6060
}
6161
return result, err
@@ -68,7 +68,7 @@ func (ec *EppoClient) GetIntegerAssignment(flagKey string, subjectKey string, su
6868
}
6969
result, ok := variation.(int64)
7070
if !ok {
71-
ec.applicationLogger.Error("failed to cast %v to int64", variation)
71+
ec.applicationLogger.Errorf("failed to cast %v to int64", variation)
7272
return defaultValue, fmt.Errorf("failed to cast %v to int64", variation)
7373
}
7474
return result, err
@@ -81,7 +81,7 @@ func (ec *EppoClient) GetStringAssignment(flagKey string, subjectKey string, sub
8181
}
8282
result, ok := variation.(string)
8383
if !ok {
84-
ec.applicationLogger.Error("failed to cast %v to string", variation)
84+
ec.applicationLogger.Errorf("failed to cast %v to string", variation)
8585
return defaultValue, fmt.Errorf("failed to cast %v to string", variation)
8686
}
8787
return result, err
@@ -110,7 +110,7 @@ func (ec *EppoClient) GetBanditAction(flagKey string, subjectKey string, subject
110110
variation = defaultVariation
111111
}
112112

113-
// If no acctions have been passed, we will return the variation, even if it is a bandit key
113+
// If no actions have been passed, we will return the variation, even if it is a bandit key
114114
if len(actions) == 0 {
115115
return BanditResult{
116116
Variation: variation,
@@ -192,19 +192,19 @@ func (ec *EppoClient) getAssignment(config configuration, flagKey string, subjec
192192

193193
flag, err := config.getFlagConfiguration(flagKey)
194194
if err != nil {
195-
ec.applicationLogger.Info("failed to get flag configuration: %v", err)
195+
ec.applicationLogger.Infof("failed to get flag configuration: %v", err)
196196
return nil, err
197197
}
198198

199199
err = flag.verifyType(variationType)
200200
if err != nil {
201-
ec.applicationLogger.Info("failed to verify flag type: %v", err)
201+
ec.applicationLogger.Warnf("failed to verify flag type: %v", err)
202202
return nil, err
203203
}
204204

205205
assignmentValue, assignmentEvent, err := flag.eval(subjectKey, subjectAttributes, ec.applicationLogger)
206206
if err != nil {
207-
ec.applicationLogger.Info("failed to evaluate flag: %v", err)
207+
ec.applicationLogger.Errorf("failed to evaluate flag: %v", err)
208208
return nil, err
209209
}
210210

@@ -214,7 +214,7 @@ func (ec *EppoClient) getAssignment(config configuration, flagKey string, subjec
214214
defer func() {
215215
r := recover()
216216
if r != nil {
217-
ec.applicationLogger.Error("panic occurred: %v", r)
217+
ec.applicationLogger.Errorf("panic occurred: %v", r)
218218
}
219219
}()
220220

eppoclient/utils_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func TestToFloat64(t *testing.T) {
3737
t.Errorf("ToFloat64(%v) error = %v, expectErr %v", tt.input, err, tt.expectErr)
3838
return
3939
}
40-
closeEnough := math.Abs(result - tt.expected)/tt.expected < 0.00001
40+
closeEnough := math.Abs(result-tt.expected)/tt.expected < 0.00001
4141
if !tt.expectErr && !closeEnough {
4242
t.Errorf("ToFloat64(%v) = %v, want %v", tt.input, result, tt.expected)
4343
}

0 commit comments

Comments
 (0)