-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlog_reporter.go
42 lines (35 loc) · 1.47 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
// Original source: github.com/micro/micro/v3/metrics/logging/reporter.go
package logbus
import (
"time"
"github.com/prometheus/client_golang/prometheus"
"go.uber.org/zap"
)
// logReporter is an implementation of monitor.logReporter:
type logReporter struct {
lg *StdLogger
}
// newLogReporter returns a configured logging reporter:
func newLogReporter() *logReporter {
logger := &logReporter{
lg: gMonitorLogger,
}
logger.lg.DebugWithChannel(Monitor, zap.String("start", "monitor will be logged"))
// logger.lg.SetZLogger(logger.lg.WithOptions(zap.AddCallerSkip(0)))
return logger
}
// Count implements the monitor.logReporter interface Count method:
func (r *logReporter) Count(metricName string, value int64, labels prometheus.Labels) error {
r.lg.InfoWithChannel(Monitor, zap.String("type", "Count"), zap.Int64(metricName, value), zap.Any("labels", labels))
return nil
}
// Gauge implements the monitor.logReporter interface Gauge method:
func (r *logReporter) Gauge(metricName string, value float64, labels prometheus.Labels) error {
r.lg.InfoWithChannel(Monitor, zap.String("type", "Gauge"), zap.Float64(metricName, value), zap.Any("labels", labels))
return nil
}
// Timing implements the monitor.logReporter interface Timing method:
func (r *logReporter) Timing(metricName string, value time.Duration, labels prometheus.Labels) error {
r.lg.InfoWithChannel(Monitor, zap.String("type", "Timing"), zap.String(metricName, value.String()), zap.Any("labels", labels))
return nil
}