-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
log_reporter.go
101 lines (88 loc) · 2.41 KB
/
log_reporter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package stats
import (
"time"
"github.com/uber-go/tally/v4"
"go.uber.org/zap"
)
// NewLogReporter returns a tally reporter that logs to the provided logger at debug level. This is useful for
// local development where the usual sinks are not available or refreshing the prometheus endpoint is not desirable.
func NewLogReporter(logger *zap.Logger) tally.StatsReporter {
return &logReporter{logger: logger}
}
type logReporter struct {
logger *zap.Logger
}
// Capabilities interface.
func (r *logReporter) Reporting() bool {
return true
}
func (r *logReporter) Tagging() bool {
return true
}
func (r *logReporter) Capabilities() tally.Capabilities {
return r
}
// Reporter interface.
func (r *logReporter) Flush() {
// Silence.
}
func (r *logReporter) ReportCounter(name string, tags map[string]string, value int64) {
r.logger.Debug("counter",
zap.String("name", name),
zap.Int64("value", value),
zap.Any("tags", tags),
zap.String("type", "counter"),
)
}
func (r *logReporter) ReportGauge(name string, tags map[string]string, value float64) {
r.logger.Debug("gauge",
zap.String("name", name),
zap.Float64("value", value),
zap.Any("tags", tags),
zap.String("type", "gauge"),
)
}
func (r *logReporter) ReportTimer(name string, tags map[string]string, interval time.Duration) {
r.logger.Debug("timer",
zap.String("name", name),
zap.Duration("value", interval),
zap.Any("tags", tags),
zap.String("type", "timer"),
)
}
func (r *logReporter) ReportHistogramValueSamples(
name string,
tags map[string]string,
buckets tally.Buckets,
bucketLowerBound,
bucketUpperBound float64,
samples int64,
) {
r.logger.Debug("histogram",
zap.String("name", name),
zap.Float64s("buckets", buckets.AsValues()),
zap.Float64("bucketLowerBound", bucketLowerBound),
zap.Float64("bucketUpperBound", bucketUpperBound),
zap.Int64("samples", samples),
zap.Any("tags", tags),
zap.String("type", "valueHistogram"),
)
}
func (r *logReporter) ReportHistogramDurationSamples(
name string,
tags map[string]string,
buckets tally.Buckets,
bucketLowerBound,
bucketUpperBound time.Duration,
samples int64,
) {
r.logger.Debug("histogram",
zap.String("name", name),
zap.Durations("buckets", buckets.AsDurations()),
zap.Duration("bucketLowerBound", bucketLowerBound),
zap.Duration("bucketUpperBound", bucketUpperBound),
zap.Int64("samples", samples),
zap.Any("tags", tags),
zap.String("type", "durationHistogram"),
)
}