mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Changes on function/metric loggers (#343)
* initial fix logger * dix DefaultFuncLogger * fix runner and tests * reverting: sending async task stdout to func logger
This commit is contained in:
53
api/runner/metric_logger.go
Normal file
53
api/runner/metric_logger.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package runner
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/iron-io/runner/common"
|
||||
)
|
||||
|
||||
type MetricLogger interface {
|
||||
Log(context.Context, map[string]interface{})
|
||||
LogCount(context.Context, string, int)
|
||||
LogGauge(context.Context, string, int)
|
||||
LogTime(context.Context, string, time.Duration)
|
||||
}
|
||||
|
||||
type Metric map[string]interface{}
|
||||
|
||||
func NewMetricLogger() MetricLogger {
|
||||
return &DefaultMetricLogger{}
|
||||
}
|
||||
|
||||
type DefaultMetricLogger struct{}
|
||||
|
||||
func (l *DefaultMetricLogger) Log(ctx context.Context, metric map[string]interface{}) {
|
||||
log := common.Logger(ctx)
|
||||
log.WithFields(logrus.Fields(metric)).Info()
|
||||
}
|
||||
|
||||
func (l *DefaultMetricLogger) LogCount(ctx context.Context, name string, value int) {
|
||||
l.Log(ctx, Metric{
|
||||
"name": name,
|
||||
"value": value,
|
||||
"type": "count",
|
||||
})
|
||||
}
|
||||
|
||||
func (l *DefaultMetricLogger) LogTime(ctx context.Context, name string, value time.Duration) {
|
||||
l.Log(ctx, Metric{
|
||||
"name": name,
|
||||
"value": value,
|
||||
"type": "time",
|
||||
})
|
||||
}
|
||||
|
||||
func (l *DefaultMetricLogger) LogGauge(ctx context.Context, name string, value int) {
|
||||
l.Log(ctx, Metric{
|
||||
"name": name,
|
||||
"value": value,
|
||||
"type": "gauge",
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user