Skip to content

Commit b5f324a

Browse files
authored
avoid concurrent map writes (#380)
1 parent 9453d84 commit b5f324a

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

log/log.go

+12-7
Original file line numberDiff line numberDiff line change
@@ -26,33 +26,38 @@ func SetupLog(l string) error {
2626
return nil
2727
}
2828

29-
// Fields is identical to logrus.Fields
30-
type Fields log.Fields
29+
// Fields is a wrapper for logrus.Entry
30+
// we need to insert some sentry captures here
31+
type Fields struct {
32+
e *log.Entry
33+
}
3134

3235
// WithField .
3336
func (f Fields) WithField(key string, value interface{}) Fields {
34-
f[key] = value
35-
return f
37+
e := f.e.WithField(key, value)
38+
return Fields{e: e}
3639
}
3740

3841
// Errorf sends sentry message
3942
func (f Fields) Errorf(format string, args ...interface{}) {
4043
sentry.CaptureMessage(fmt.Sprintf(format, args...))
41-
log.WithFields(log.Fields(f)).Errorf(format, args...)
44+
f.e.Errorf(format, args...)
4245
}
4346

4447
// Err is a decorator returning the argument
4548
func (f Fields) Err(err error) error {
4649
if err != nil {
4750
sentry.CaptureMessage(fmt.Sprintf("%+v", err))
48-
log.WithFields(log.Fields(f)).Errorf("%+v", err)
51+
f.e.Errorf("%+v", err)
4952
}
5053
return err
5154
}
5255

5356
// WithField add kv into log entry
5457
func WithField(key string, value interface{}) Fields {
55-
return Fields{key: value}
58+
return Fields{
59+
e: log.WithField(key, value),
60+
}
5661
}
5762

5863
// Error forwards to sentry

0 commit comments

Comments
 (0)