mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
metric logger
This commit is contained in:
@@ -1,27 +1,24 @@
|
||||
package runner
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
titancommon "github.com/iron-io/titan/common"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
func LogMetric(ctx context.Context, name string, metricType string, value interface{}) {
|
||||
type Logger interface {
|
||||
Log(context.Context, map[string]interface{})
|
||||
}
|
||||
|
||||
type Metric map[string]interface{}
|
||||
|
||||
func NewMetricLogger() *MetricLogger {
|
||||
return &MetricLogger{}
|
||||
}
|
||||
|
||||
type MetricLogger struct{}
|
||||
|
||||
func (l *MetricLogger) Log(ctx context.Context, metric map[string]interface{}) {
|
||||
log := titancommon.Logger(ctx)
|
||||
log.WithFields(logrus.Fields{
|
||||
"metric": name, "type": metricType, "value": value}).Info()
|
||||
}
|
||||
|
||||
func LogMetricGauge(ctx context.Context, name string, value int) {
|
||||
LogMetric(ctx, name, "gauge", value)
|
||||
}
|
||||
|
||||
func LogMetricCount(ctx context.Context, name string, value int) {
|
||||
LogMetric(ctx, name, "count", value)
|
||||
}
|
||||
|
||||
func LogMetricTime(ctx context.Context, name string, time time.Duration) {
|
||||
LogMetric(ctx, name, "time", time)
|
||||
log.WithFields(logrus.Fields(metric)).Info()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user