diff --git a/services/diagnostic/handlers.go b/services/diagnostic/handlers.go index 7f8d632211..e03be1bf33 100644 --- a/services/diagnostic/handlers.go +++ b/services/diagnostic/handlers.go @@ -17,6 +17,7 @@ import ( "github.com/influxdata/kapacitor/models" alertservice "github.com/influxdata/kapacitor/services/alert" "github.com/influxdata/kapacitor/services/alerta" + klog "github.com/influxdata/kapacitor/services/diagnostic/internal/log" "github.com/influxdata/kapacitor/services/hipchat" "github.com/influxdata/kapacitor/services/httppost" "github.com/influxdata/kapacitor/services/influxdb" @@ -35,37 +36,35 @@ import ( "github.com/influxdata/kapacitor/services/udp" "github.com/influxdata/kapacitor/services/victorops" plog "github.com/prometheus/common/log" - "go.uber.org/zap" - "go.uber.org/zap/zapcore" ) -func Error(l *zap.Logger, msg string, err error, ctx []keyvalue.T) { +func Error(l *klog.Logger, msg string, err error, ctx []keyvalue.T) { if len(ctx) == 0 { - l.Error(msg, zap.Error(err)) + l.Error(msg, klog.Error(err)) return } if len(ctx) == 1 { el := ctx[0] - l.Error(msg, zap.Error(err), zap.String(el.Key, el.Value)) + l.Error(msg, klog.Error(err), klog.String(el.Key, el.Value)) return } if len(ctx) == 2 { x := ctx[0] y := ctx[1] - l.Error(msg, zap.Error(err), zap.String(x.Key, x.Value), zap.String(y.Key, y.Value)) + l.Error(msg, klog.Error(err), klog.String(x.Key, x.Value), klog.String(y.Key, y.Value)) return } // This isn't great wrt to allocation, but should be rare. Currently // no calls to Error use more than 2 ctx values. If a new call to // Error uses more than 2, update this function - fields := make([]zapcore.Field, len(ctx)+1) // +1 for error - fields[0] = zap.Error(err) + fields := make([]klog.Field, len(ctx)+1) // +1 for error + fields[0] = klog.Error(err) for i := 1; i < len(fields); i++ { kv := ctx[i-1] - fields[i] = zap.String(kv.Key, kv.Value) + fields[i] = klog.String(kv.Key, kv.Value) } l.Error(msg, fields...) @@ -74,13 +73,13 @@ func Error(l *zap.Logger, msg string, err error, ctx []keyvalue.T) { // Alert Service Handler type AlertServiceHandler struct { - l *zap.Logger + l *klog.Logger } -func zapFieldsFromContext(ctx []keyvalue.T) []zapcore.Field { - fields := make([]zapcore.Field, len(ctx)) +func zapFieldsFromContext(ctx []keyvalue.T) []klog.Field { + fields := make([]klog.Field, len(ctx)) for i, kv := range ctx { - fields[i] = zap.String(kv.Key, kv.Value) + fields[i] = klog.String(kv.Key, kv.Value) } return fields @@ -99,19 +98,19 @@ func (h *AlertServiceHandler) MigratingHandlerSpecs() { } func (h *AlertServiceHandler) MigratingOldHandlerSpec(spec string) { - h.l.Debug("migrating old handler spec", zap.String("handler", spec)) + h.l.Debug("migrating old handler spec", klog.String("handler", spec)) } func (h *AlertServiceHandler) FoundHandlerRows(length int) { - h.l.Debug("found handler rows", zap.Int("handler_row_count", length)) + h.l.Debug("found handler rows", klog.Int("handler_row_count", length)) } func (h *AlertServiceHandler) CreatingNewHandlers(length int) { - h.l.Debug("creating new handlers in place of old handlers", zap.Int("handler_row_count", length)) + h.l.Debug("creating new handlers in place of old handlers", klog.Int("handler_row_count", length)) } func (h *AlertServiceHandler) FoundNewHandler(key string) { - h.l.Debug("found new handler skipping", zap.String("handler", key)) + h.l.Debug("found new handler skipping", klog.String("handler", key)) } func (h *AlertServiceHandler) Error(msg string, err error, ctx ...keyvalue.T) { @@ -121,30 +120,30 @@ func (h *AlertServiceHandler) Error(msg string, err error, ctx ...keyvalue.T) { // Kapcitor Handler type KapacitorHandler struct { - l *zap.Logger + l *klog.Logger } func (h *KapacitorHandler) WithTaskContext(task string) kapacitor.TaskDiagnostic { return &KapacitorHandler{ - l: h.l.With(zap.String("task", task)), + l: h.l.With(klog.String("task", task)), } } func (h *KapacitorHandler) WithTaskMasterContext(tm string) kapacitor.Diagnostic { return &KapacitorHandler{ - l: h.l.With(zap.String("task_master", tm)), + l: h.l.With(klog.String("task_master", tm)), } } func (h *KapacitorHandler) WithNodeContext(node string) kapacitor.NodeDiagnostic { return &KapacitorHandler{ - l: h.l.With(zap.String("node", node)), + l: h.l.With(klog.String("node", node)), } } func (h *KapacitorHandler) WithEdgeContext(task, parent, child string) kapacitor.EdgeDiagnostic { return &KapacitorHandler{ - l: h.l.With(zap.String("task", task), zap.String("parent", parent), zap.String("child", child)), + l: h.l.With(klog.String("task", task), klog.String("parent", parent), klog.String("child", child)), } } @@ -157,27 +156,27 @@ func (h *KapacitorHandler) TaskMasterClosed() { } func (h *KapacitorHandler) StartingTask(task string) { - h.l.Debug("starting task", zap.String("task", task)) + h.l.Debug("starting task", klog.String("task", task)) } func (h *KapacitorHandler) StartedTask(task string) { - h.l.Info("started task", zap.String("task", task)) + h.l.Info("started task", klog.String("task", task)) } func (h *KapacitorHandler) StoppedTask(task string) { - h.l.Info("stopped task", zap.String("task", task)) + h.l.Info("stopped task", klog.String("task", task)) } func (h *KapacitorHandler) StoppedTaskWithError(task string, err error) { - h.l.Error("failed to stop task with out error", zap.String("task", task), zap.Error(err)) + h.l.Error("failed to stop task with out error", klog.String("task", task), klog.Error(err)) } func (h *KapacitorHandler) TaskMasterDot(d string) { - h.l.Debug("listing dot", zap.String("dot", d)) + h.l.Debug("listing dot", klog.String("dot", d)) } func (h *KapacitorHandler) ClosingEdge(collected int64, emitted int64) { - h.l.Debug("closing edge", zap.Int64("collected", collected), zap.Int64("emitted", emitted)) + h.l.Debug("closing edge", klog.Int64("collected", collected), klog.Int64("emitted", emitted)) } func (h *KapacitorHandler) Error(msg string, err error, ctx ...keyvalue.T) { @@ -186,23 +185,23 @@ func (h *KapacitorHandler) Error(msg string, err error, ctx ...keyvalue.T) { func (h *KapacitorHandler) AlertTriggered(level alert.Level, id string, message string, rows *models.Row) { h.l.Debug("alert triggered", - zap.Stringer("level", level), - zap.String("id", id), - zap.String("event_message", message), - zap.String("data", fmt.Sprintf("%v", rows)), + klog.Stringer("level", level), + klog.String("id", id), + klog.String("event_message", message), + klog.String("data", fmt.Sprintf("%v", rows)), ) } func (h *KapacitorHandler) SettingReplicas(new int, old int, id string) { h.l.Debug("setting replicas", - zap.Int("new", new), - zap.Int("old", old), - zap.String("event_id", id), + klog.Int("new", new), + klog.Int("old", old), + klog.String("event_id", id), ) } func (h *KapacitorHandler) StartingBatchQuery(q string) { - h.l.Debug("starting next batch query", zap.String("query", q)) + h.l.Debug("starting next batch query", klog.String("query", q)) } func TagPairs(tags models.Tags) []string { @@ -224,19 +223,19 @@ func FieldPairs(tags models.Fields) []string { } func (h *KapacitorHandler) LogPointData(level, prefix string, point edge.PointMessage) { - fields := []zapcore.Field{ - zap.String("prefix", prefix), - zap.String("name", point.Name()), - zap.String("db", point.Database()), - zap.String("rp", point.RetentionPolicy()), - zap.String("group", string(point.GroupID())), - zap.Strings("dimensions", point.Dimensions().TagNames), - zap.Strings("tags", TagPairs(point.Tags())), - zap.Strings("fields", FieldPairs(point.Fields())), - zap.Time("time", point.Time()), + fields := []klog.Field{ + klog.String("prefix", prefix), + klog.String("name", point.Name()), + klog.String("db", point.Database()), + klog.String("rp", point.RetentionPolicy()), + klog.String("group", string(point.GroupID())), + klog.Strings("dimensions", point.Dimensions().TagNames), + klog.Strings("tags", TagPairs(point.Tags())), + klog.Strings("fields", FieldPairs(point.Fields())), + klog.Time("time", point.Time()), } - var log func(string, ...zapcore.Field) + var log func(string, ...klog.Field) switch level { case "INFO": @@ -255,7 +254,7 @@ func (h *KapacitorHandler) LogPointData(level, prefix string, point edge.PointMe } func (h *KapacitorHandler) LogBatchData(level, prefix string, batch edge.BufferedBatchMessage) { - var log func(string, ...zapcore.Field) + var log func(string, ...klog.Field) switch level { case "INFO": @@ -272,41 +271,41 @@ func (h *KapacitorHandler) LogBatchData(level, prefix string, batch edge.Buffere begin := batch.Begin() log("begin batch", - zap.String("prefix", prefix), - zap.String("name", begin.Name()), - zap.String("group", string(begin.GroupID())), - zap.Strings("tags", TagPairs(begin.Tags())), - zap.Time("time", begin.Time()), + klog.String("prefix", prefix), + klog.String("name", begin.Name()), + klog.String("group", string(begin.GroupID())), + klog.Strings("tags", TagPairs(begin.Tags())), + klog.Time("time", begin.Time()), ) for _, p := range batch.Points() { log("batch point", - zap.String("prefix", prefix), - zap.String("name", begin.Name()), - zap.String("group", string(begin.GroupID())), - zap.Strings("tags", TagPairs(p.Tags())), - zap.Strings("fields", FieldPairs(p.Fields())), - zap.Time("time", p.Time()), + klog.String("prefix", prefix), + klog.String("name", begin.Name()), + klog.String("group", string(begin.GroupID())), + klog.Strings("tags", TagPairs(p.Tags())), + klog.Strings("fields", FieldPairs(p.Fields())), + klog.Time("time", p.Time()), ) } log("End batch", - zap.String("prefix", prefix), - zap.String("name", begin.Name()), - zap.String("group", string(begin.GroupID())), - zap.Strings("tags", TagPairs(begin.Tags())), - zap.Time("time", begin.Time()), + klog.String("prefix", prefix), + klog.String("name", begin.Name()), + klog.String("group", string(begin.GroupID())), + klog.Strings("tags", TagPairs(begin.Tags())), + klog.Time("time", begin.Time()), ) } func (h *KapacitorHandler) UDFLog(s string) { - h.l.Info("UDF log", zap.String("text", s)) + h.l.Info("UDF log", klog.String("text", s)) } // Alerta handler type AlertaHandler struct { - l *zap.Logger + l *klog.Logger } func (h *AlertaHandler) WithContext(ctx ...keyvalue.T) alerta.Diagnostic { @@ -318,16 +317,16 @@ func (h *AlertaHandler) WithContext(ctx ...keyvalue.T) alerta.Diagnostic { } func (h *AlertaHandler) TemplateError(err error, kv keyvalue.T) { - h.l.Error("failed to evaluate Alerta template", zap.Error(err), zap.String(kv.Key, kv.Value)) + h.l.Error("failed to evaluate Alerta template", klog.Error(err), klog.String(kv.Key, kv.Value)) } func (h *AlertaHandler) Error(msg string, err error) { - h.l.Error(msg, zap.Error(err)) + h.l.Error(msg, klog.Error(err)) } // HipChat handler type HipChatHandler struct { - l *zap.Logger + l *klog.Logger } func (h *HipChatHandler) WithContext(ctx ...keyvalue.T) hipchat.Diagnostic { @@ -339,18 +338,18 @@ func (h *HipChatHandler) WithContext(ctx ...keyvalue.T) hipchat.Diagnostic { } func (h *HipChatHandler) Error(msg string, err error) { - h.l.Error(msg, zap.Error(err)) + h.l.Error(msg, klog.Error(err)) } // HTTPD handler type HTTPDHandler struct { - l *zap.Logger + l *klog.Logger } func (h *HTTPDHandler) NewHTTPServerErrorLogger() *log.Logger { s := &StaticLevelHandler{ - l: h.l.With(zap.String("service", "httpd_server_errors")), + l: h.l.With(klog.String("service", "httpd_server_errors")), level: llError, } @@ -370,15 +369,15 @@ func (h *HTTPDHandler) ShutdownTimeout() { } func (h *HTTPDHandler) AuthenticationEnabled(enabled bool) { - h.l.Info("authentication", zap.Bool("enabled", enabled)) + h.l.Info("authentication", klog.Bool("enabled", enabled)) } func (h *HTTPDHandler) ListeningOn(addr string, proto string) { - h.l.Info("listening on", zap.String("addr", addr), zap.String("protocol", proto)) + h.l.Info("listening on", klog.String("addr", addr), klog.String("protocol", proto)) } func (h *HTTPDHandler) WriteBodyReceived(body string) { - h.l.Debug("write body received by handler: %s", zap.String("body", body)) + h.l.Debug("write body received by handler: %s", klog.String("body", body)) } func (h *HTTPDHandler) HTTP( @@ -395,17 +394,17 @@ func (h *HTTPDHandler) HTTP( duration time.Duration, ) { h.l.Info("http request", - zap.String("host", host), - zap.String("username", username), - zap.Time("start", start), - zap.String("method", method), - zap.String("uri", uri), - zap.String("protocol", proto), - zap.Int("status", status), - zap.String("referer", referer), - zap.String("user-agent", userAgent), - zap.String("request-id", reqID), - zap.Duration("duration", duration), + klog.String("host", host), + klog.String("username", username), + klog.Time("start", start), + klog.String("method", method), + klog.String("uri", uri), + klog.String("protocol", proto), + klog.Int("status", status), + klog.String("referer", referer), + klog.String("user-agent", userAgent), + klog.String("request-id", reqID), + klog.Duration("duration", duration), ) } @@ -426,37 +425,37 @@ func (h *HTTPDHandler) RecoveryError( ) { h.l.Error( msg, - zap.String("err", err), - zap.String("host", host), - zap.String("username", username), - zap.Time("start", start), - zap.String("method", method), - zap.String("uri", uri), - zap.String("protocol", proto), - zap.Int("status", status), - zap.String("referer", referer), - zap.String("user-agent", userAgent), - zap.String("request-id", reqID), - zap.Duration("duration", duration), + klog.String("err", err), + klog.String("host", host), + klog.String("username", username), + klog.Time("start", start), + klog.String("method", method), + klog.String("uri", uri), + klog.String("protocol", proto), + klog.Int("status", status), + klog.String("referer", referer), + klog.String("user-agent", userAgent), + klog.String("request-id", reqID), + klog.Duration("duration", duration), ) } func (h *HTTPDHandler) Error(msg string, err error) { - h.l.Error(msg, zap.Error(err)) + h.l.Error(msg, klog.Error(err)) } // Reporting handler type ReportingHandler struct { - l *zap.Logger + l *klog.Logger } func (h *ReportingHandler) Error(msg string, err error) { - h.l.Error(msg, zap.Error(err)) + h.l.Error(msg, klog.Error(err)) } // PagerDuty handler type PagerDutyHandler struct { - l *zap.Logger + l *klog.Logger } func (h *PagerDutyHandler) WithContext(ctx ...keyvalue.T) pagerduty.Diagnostic { @@ -468,13 +467,13 @@ func (h *PagerDutyHandler) WithContext(ctx ...keyvalue.T) pagerduty.Diagnostic { } func (h *PagerDutyHandler) Error(msg string, err error) { - h.l.Error(msg, zap.Error(err)) + h.l.Error(msg, klog.Error(err)) } // Slack Handler type SlackHandler struct { - l *zap.Logger + l *klog.Logger } func (h *SlackHandler) InsecureSkipVerify() { @@ -482,7 +481,7 @@ func (h *SlackHandler) InsecureSkipVerify() { } func (h *SlackHandler) Error(msg string, err error) { - h.l.Error(msg, zap.Error(err)) + h.l.Error(msg, klog.Error(err)) } func (h *SlackHandler) WithContext(ctx ...keyvalue.T) slack.Diagnostic { @@ -496,29 +495,29 @@ func (h *SlackHandler) WithContext(ctx ...keyvalue.T) slack.Diagnostic { // Storage Handler type StorageHandler struct { - l *zap.Logger + l *klog.Logger } func (h *StorageHandler) Error(msg string, err error) { - h.l.Error(msg, zap.Error(err)) + h.l.Error(msg, klog.Error(err)) } // TaskStore Handler type TaskStoreHandler struct { - l *zap.Logger + l *klog.Logger } func (h *TaskStoreHandler) StartingTask(taskID string) { - h.l.Debug("starting enabled task on startup", zap.String("task", taskID)) + h.l.Debug("starting enabled task on startup", klog.String("task", taskID)) } func (h *TaskStoreHandler) StartedTask(taskID string) { - h.l.Debug("started task during startup", zap.String("task", taskID)) + h.l.Debug("started task during startup", klog.String("task", taskID)) } func (h *TaskStoreHandler) FinishedTask(taskID string) { - h.l.Debug("task finished", zap.String("task", taskID)) + h.l.Debug("task finished", klog.String("task", taskID)) } func (h *TaskStoreHandler) Debug(msg string) { @@ -530,21 +529,21 @@ func (h *TaskStoreHandler) Error(msg string, err error, ctx ...keyvalue.T) { } func (h *TaskStoreHandler) AlreadyMigrated(entity, id string) { - h.l.Debug("entity has already been migrated skipping", zap.String(entity, id)) + h.l.Debug("entity has already been migrated skipping", klog.String(entity, id)) } func (h *TaskStoreHandler) Migrated(entity, id string) { - h.l.Debug("entity was migrated to new storage service", zap.String(entity, id)) + h.l.Debug("entity was migrated to new storage service", klog.String(entity, id)) } // VictorOps Handler type VictorOpsHandler struct { - l *zap.Logger + l *klog.Logger } func (h *VictorOpsHandler) Error(msg string, err error) { - h.l.Error(msg, zap.Error(err)) + h.l.Error(msg, klog.Error(err)) } func (h *VictorOpsHandler) WithContext(ctx ...keyvalue.T) victorops.Diagnostic { @@ -556,11 +555,11 @@ func (h *VictorOpsHandler) WithContext(ctx ...keyvalue.T) victorops.Diagnostic { } type SMTPHandler struct { - l *zap.Logger + l *klog.Logger } func (h *SMTPHandler) Error(msg string, err error) { - h.l.Error(msg, zap.Error(err)) + h.l.Error(msg, klog.Error(err)) } func (h *SMTPHandler) WithContext(ctx ...keyvalue.T) smtp.Diagnostic { @@ -572,11 +571,11 @@ func (h *SMTPHandler) WithContext(ctx ...keyvalue.T) smtp.Diagnostic { } type OpsGenieHandler struct { - l *zap.Logger + l *klog.Logger } func (h *OpsGenieHandler) Error(msg string, err error) { - h.l.Error(msg, zap.Error(err)) + h.l.Error(msg, klog.Error(err)) } func (h *OpsGenieHandler) WithContext(ctx ...keyvalue.T) opsgenie.Diagnostic { @@ -590,21 +589,21 @@ func (h *OpsGenieHandler) WithContext(ctx ...keyvalue.T) opsgenie.Diagnostic { // UDF service handler type UDFServiceHandler struct { - l *zap.Logger + l *klog.Logger } func (h *UDFServiceHandler) LoadedUDFInfo(udf string) { - h.l.Debug("loaded UDF info", zap.String("udf", udf)) + h.l.Debug("loaded UDF info", klog.String("udf", udf)) } // Pushover handler type PushoverHandler struct { - l *zap.Logger + l *klog.Logger } func (h *PushoverHandler) Error(msg string, err error) { - h.l.Error(msg, zap.Error(err)) + h.l.Error(msg, klog.Error(err)) } func (h *PushoverHandler) WithContext(ctx ...keyvalue.T) pushover.Diagnostic { @@ -618,11 +617,11 @@ func (h *PushoverHandler) WithContext(ctx ...keyvalue.T) pushover.Diagnostic { // Template handler type HTTPPostHandler struct { - l *zap.Logger + l *klog.Logger } func (h *HTTPPostHandler) Error(msg string, err error) { - h.l.Error(msg, zap.Error(err)) + h.l.Error(msg, klog.Error(err)) } func (h *HTTPPostHandler) WithContext(ctx ...keyvalue.T) httppost.Diagnostic { @@ -636,7 +635,7 @@ func (h *HTTPPostHandler) WithContext(ctx ...keyvalue.T) httppost.Diagnostic { // Sensu handler type SensuHandler struct { - l *zap.Logger + l *klog.Logger } func (h *SensuHandler) Error(msg string, err error, ctx ...keyvalue.T) { @@ -654,11 +653,11 @@ func (h *SensuHandler) WithContext(ctx ...keyvalue.T) sensu.Diagnostic { // SNMPTrap handler type SNMPTrapHandler struct { - l *zap.Logger + l *klog.Logger } func (h *SNMPTrapHandler) Error(msg string, err error) { - h.l.Error(msg, zap.Error(err)) + h.l.Error(msg, klog.Error(err)) } func (h *SNMPTrapHandler) WithContext(ctx ...keyvalue.T) snmptrap.Diagnostic { @@ -672,11 +671,11 @@ func (h *SNMPTrapHandler) WithContext(ctx ...keyvalue.T) snmptrap.Diagnostic { // Telegram handler type TelegramHandler struct { - l *zap.Logger + l *klog.Logger } func (h *TelegramHandler) Error(msg string, err error) { - h.l.Error(msg, zap.Error(err)) + h.l.Error(msg, klog.Error(err)) } func (h *TelegramHandler) WithContext(ctx ...keyvalue.T) telegram.Diagnostic { @@ -690,20 +689,20 @@ func (h *TelegramHandler) WithContext(ctx ...keyvalue.T) telegram.Diagnostic { // MQTT handler type MQTTHandler struct { - l *zap.Logger + l *klog.Logger } func (h *MQTTHandler) Error(msg string, err error) { - h.l.Error(msg, zap.Error(err)) + h.l.Error(msg, klog.Error(err)) } func (h *MQTTHandler) CreatingAlertHandler(c mqtt.HandlerConfig) { qos, _ := c.QoS.MarshalText() h.l.Debug("creating mqtt handler", - zap.String("broker_name", c.BrokerName), - zap.String("topic", c.Topic), - zap.Bool("retained", c.Retained), - zap.String("qos", string(qos)), + klog.String("broker_name", c.BrokerName), + klog.String("topic", c.Topic), + klog.Bool("retained", c.Retained), + klog.String("qos", string(qos)), ) } @@ -722,11 +721,11 @@ func (h *MQTTHandler) WithContext(ctx ...keyvalue.T) mqtt.Diagnostic { // Talk handler type TalkHandler struct { - l *zap.Logger + l *klog.Logger } func (h *TalkHandler) Error(msg string, err error) { - h.l.Error(msg, zap.Error(err)) + h.l.Error(msg, klog.Error(err)) } func (h *TalkHandler) WithContext(ctx ...keyvalue.T) talk.Diagnostic { @@ -740,15 +739,15 @@ func (h *TalkHandler) WithContext(ctx ...keyvalue.T) talk.Diagnostic { // Config handler type ConfigOverrideHandler struct { - l *zap.Logger + l *klog.Logger } func (h *ConfigOverrideHandler) Error(msg string, err error) { - h.l.Error(msg, zap.Error(err)) + h.l.Error(msg, klog.Error(err)) } type ServerHandler struct { - l *zap.Logger + l *klog.Logger } func (h *ServerHandler) Error(msg string, err error, ctx ...keyvalue.T) { @@ -763,21 +762,21 @@ func (h *ServerHandler) Info(msg string, ctx ...keyvalue.T) { if len(ctx) == 1 { el := ctx[0] - h.l.Info(msg, zap.String(el.Key, el.Value)) + h.l.Info(msg, klog.String(el.Key, el.Value)) return } if len(ctx) == 2 { x := ctx[0] y := ctx[1] - h.l.Info(msg, zap.String(x.Key, x.Value), zap.String(y.Key, y.Value)) + h.l.Info(msg, klog.String(x.Key, x.Value), klog.String(y.Key, y.Value)) return } - fields := make([]zapcore.Field, len(ctx)) + fields := make([]klog.Field, len(ctx)) for i := 0; i < len(fields); i++ { kv := ctx[i] - fields[i] = zap.String(kv.Key, kv.Value) + fields[i] = klog.String(kv.Key, kv.Value) } h.l.Info(msg, fields...) @@ -791,28 +790,28 @@ func (h *ServerHandler) Debug(msg string, ctx ...keyvalue.T) { if len(ctx) == 1 { el := ctx[0] - h.l.Debug(msg, zap.String(el.Key, el.Value)) + h.l.Debug(msg, klog.String(el.Key, el.Value)) return } if len(ctx) == 2 { x := ctx[0] y := ctx[1] - h.l.Debug(msg, zap.String(x.Key, x.Value), zap.String(y.Key, y.Value)) + h.l.Debug(msg, klog.String(x.Key, x.Value), klog.String(y.Key, y.Value)) return } - fields := make([]zapcore.Field, len(ctx)) + fields := make([]klog.Field, len(ctx)) for i := 0; i < len(fields); i++ { kv := ctx[i] - fields[i] = zap.String(kv.Key, kv.Value) + fields[i] = klog.String(kv.Key, kv.Value) } h.l.Debug(msg, fields...) } type ReplayHandler struct { - l *zap.Logger + l *klog.Logger } func (h *ReplayHandler) Error(msg string, err error, ctx ...keyvalue.T) { @@ -827,21 +826,21 @@ func (h *ReplayHandler) Debug(msg string, ctx ...keyvalue.T) { if len(ctx) == 1 { el := ctx[0] - h.l.Debug(msg, zap.String(el.Key, el.Value)) + h.l.Debug(msg, klog.String(el.Key, el.Value)) return } if len(ctx) == 2 { x := ctx[0] y := ctx[1] - h.l.Debug(msg, zap.String(x.Key, x.Value), zap.String(y.Key, y.Value)) + h.l.Debug(msg, klog.String(x.Key, x.Value), klog.String(y.Key, y.Value)) return } - fields := make([]zapcore.Field, len(ctx)) + fields := make([]klog.Field, len(ctx)) for i := 0; i < len(fields); i++ { kv := ctx[i] - fields[i] = zap.String(kv.Key, kv.Value) + fields[i] = klog.String(kv.Key, kv.Value) } h.l.Debug(msg, fields...) @@ -850,31 +849,31 @@ func (h *ReplayHandler) Debug(msg string, ctx ...keyvalue.T) { // K8s handler type K8sHandler struct { - l *zap.Logger + l *klog.Logger } func (h *K8sHandler) WithClusterContext(cluster string) k8s.Diagnostic { return &K8sHandler{ - l: h.l.With(zap.String("cluster_id", cluster)), + l: h.l.With(klog.String("cluster_id", cluster)), } } // Swarm handler type SwarmHandler struct { - l *zap.Logger + l *klog.Logger } func (h *SwarmHandler) WithClusterContext(cluster string) swarm.Diagnostic { return &SwarmHandler{ - l: h.l.With(zap.String("cluster_id", cluster)), + l: h.l.With(klog.String("cluster_id", cluster)), } } // Deadman handler type DeadmanHandler struct { - l *zap.Logger + l *klog.Logger } func (h *DeadmanHandler) ConfiguredGlobally() { @@ -884,11 +883,11 @@ func (h *DeadmanHandler) ConfiguredGlobally() { // NoAuth handler type NoAuthHandler struct { - l *zap.Logger + l *klog.Logger } func (h *NoAuthHandler) FakedUserAuthentication(username string) { - h.l.Warn("using noauth auth backend. Faked Authentication for user", zap.String("user", username)) + h.l.Warn("using noauth auth backend. Faked Authentication for user", klog.String("user", username)) } func (h *NoAuthHandler) FakedSubscriptionUserToken() { @@ -898,17 +897,17 @@ func (h *NoAuthHandler) FakedSubscriptionUserToken() { // Stats handler type StatsHandler struct { - l *zap.Logger + l *klog.Logger } func (h *StatsHandler) Error(msg string, err error) { - h.l.Error(msg, zap.Error(err)) + h.l.Error(msg, klog.Error(err)) } // UDP handler type UDPHandler struct { - l *zap.Logger + l *klog.Logger } func (h *UDPHandler) Error(msg string, err error, ctx ...keyvalue.T) { @@ -916,7 +915,7 @@ func (h *UDPHandler) Error(msg string, err error, ctx ...keyvalue.T) { } func (h *UDPHandler) StartedListening(addr string) { - h.l.Info("started listening on UDP", zap.String("address", addr)) + h.l.Info("started listening on UDP", klog.String("address", addr)) } func (h *UDPHandler) ClosedService() { @@ -926,7 +925,7 @@ func (h *UDPHandler) ClosedService() { // InfluxDB handler type InfluxDBHandler struct { - l *zap.Logger + l *klog.Logger } func (h *InfluxDBHandler) Error(msg string, err error, ctx ...keyvalue.T) { @@ -935,30 +934,30 @@ func (h *InfluxDBHandler) Error(msg string, err error, ctx ...keyvalue.T) { func (h *InfluxDBHandler) WithClusterContext(id string) influxdb.Diagnostic { return &InfluxDBHandler{ - l: h.l.With(zap.String("cluster", id)), + l: h.l.With(klog.String("cluster", id)), } } func (h *InfluxDBHandler) WithUDPContext(id string) udp.Diagnostic { return &UDPHandler{ - l: h.l.With(zap.String("listener_id", id)), + l: h.l.With(klog.String("listener_id", id)), } } func (h *InfluxDBHandler) InsecureSkipVerify(urls []string) { - h.l.Warn("using InsecureSkipVerify when connecting to InfluxDB; this is insecure", zap.Strings("urls", urls)) + h.l.Warn("using InsecureSkipVerify when connecting to InfluxDB; this is insecure", klog.Strings("urls", urls)) } func (h *InfluxDBHandler) UnlinkingSubscriptions(cluster string) { - h.l.Debug("unlinking subscription for cluster", zap.String("cluster", cluster)) + h.l.Debug("unlinking subscription for cluster", klog.String("cluster", cluster)) } func (h *InfluxDBHandler) LinkingSubscriptions(cluster string) { - h.l.Debug("linking subscription for cluster", zap.String("cluster", cluster)) + h.l.Debug("linking subscription for cluster", klog.String("cluster", cluster)) } func (h *InfluxDBHandler) StartedUDPListener(dbrp string) { - h.l.Info("started UDP listener", zap.String("dbrp", dbrp)) + h.l.Info("started UDP listener", klog.String("dbrp", dbrp)) } // Scraper handler @@ -966,7 +965,7 @@ func (h *InfluxDBHandler) StartedUDPListener(dbrp string) { type ScraperHandler struct { mu sync.Mutex buf *bytes.Buffer - l *zap.Logger + l *klog.Logger } func (h *ScraperHandler) Debug(ctx ...interface{}) { @@ -1063,7 +1062,7 @@ func (h *ScraperHandler) Fatal(ctx ...interface{}) { defer h.buf.Reset() fmt.Fprint(h.buf, ctx...) - h.l.Fatal(h.buf.String()) + h.l.Error(h.buf.String()) } func (h *ScraperHandler) Fatalln(ctx ...interface{}) { @@ -1072,27 +1071,27 @@ func (h *ScraperHandler) Fatalln(ctx ...interface{}) { defer h.buf.Reset() fmt.Fprintln(h.buf, ctx...) - h.l.Fatal(h.buf.String()) + h.l.Error(h.buf.String()) } func (h *ScraperHandler) Fatalf(s string, ctx ...interface{}) { - h.l.Fatal(fmt.Sprintf(s, ctx...)) + h.l.Error(fmt.Sprintf(s, ctx...)) } func (h *ScraperHandler) With(key string, value interface{}) plog.Logger { - var field zapcore.Field + var field klog.Field switch value.(type) { case int: - field = zap.Int(key, value.(int)) + field = klog.Int(key, value.(int)) case float64: - field = zap.Float64(key, value.(float64)) + field = klog.Float64(key, value.(float64)) case string: - field = zap.String(key, value.(string)) + field = klog.String(key, value.(string)) case time.Duration: - field = zap.Duration(key, value.(time.Duration)) + field = klog.Duration(key, value.(time.Duration)) default: - field = zap.String(key, fmt.Sprintf("%v", value)) + field = klog.String(key, fmt.Sprintf("%v", value)) } return &ScraperHandler{ @@ -1111,14 +1110,14 @@ func (h *ScraperHandler) SetLevel(string) error { // Edge Handler type EdgeHandler struct { - l *zap.Logger + l *klog.Logger } func (h *EdgeHandler) Collect(mtype edge.MessageType) { - h.l.Debug("collected message", zap.Stringer("message_type", mtype)) + h.l.Debug("collected message", klog.Stringer("message_type", mtype)) } func (h *EdgeHandler) Emit(mtype edge.MessageType) { - h.l.Debug("emitted message", zap.Stringer("message_type", mtype)) + h.l.Debug("emitted message", klog.Stringer("message_type", mtype)) } type logLevel int @@ -1132,7 +1131,7 @@ const ( ) type StaticLevelHandler struct { - l *zap.Logger + l *klog.Logger level logLevel } @@ -1156,19 +1155,19 @@ func (h *StaticLevelHandler) Write(buf []byte) (int, error) { // Cmd handler type CmdHandler struct { - l *zap.Logger + l *klog.Logger } func (h *CmdHandler) Error(msg string, err error) { - h.l.Error(msg, zap.Error(err)) + h.l.Error(msg, klog.Error(err)) } func (h *CmdHandler) KapacitorStarting(version, branch, commit string) { - h.l.Info("kapacitor starting", zap.String("version", version), zap.String("branch", branch), zap.String("commit", commit)) + h.l.Info("kapacitor starting", klog.String("version", version), klog.String("branch", branch), klog.String("commit", commit)) } func (h *CmdHandler) GoVersion() { - h.l.Info("go version", zap.String("version", runtime.Version())) + h.l.Info("go version", klog.String("version", runtime.Version())) } func (h *CmdHandler) Info(msg string) { diff --git a/services/diagnostic/internal/log/field.go b/services/diagnostic/internal/log/field.go new file mode 100644 index 0000000000..7a341833cb --- /dev/null +++ b/services/diagnostic/internal/log/field.go @@ -0,0 +1,417 @@ +package log + +import ( + "bufio" + "fmt" + "strconv" + "time" +) + +type Field interface { + WriteTo(w *bufio.Writer) (n int64, err error) +} + +// String +type StringField struct { + key []byte + value string +} + +func String(key string, value string) Field { + return &StringField{ + key: []byte(key), + value: value, + } +} + +func (s *StringField) WriteTo(w *bufio.Writer) (n int64, err error) { + var m int + + m, err = w.Write(s.key) + n += int64(m) + if err != nil { + return + } + + err = w.WriteByte('=') + n += 1 + if err != nil { + return + } + + // TODO: properly escape + m, err = w.WriteString(s.value) + n += int64(m) + if err != nil { + return + } + + return +} + +// Stringer +type StringerField struct { + key []byte + value fmt.Stringer +} + +func Stringer(key string, value fmt.Stringer) Field { + return &StringerField{ + key: []byte(key), + value: value, + } +} + +func (s *StringerField) WriteTo(w *bufio.Writer) (n int64, err error) { + var m int + + m, err = w.Write(s.key) + n += int64(m) + if err != nil { + return + } + + err = w.WriteByte('=') + n += 1 + if err != nil { + return + } + + // TODO: properly escape + m, err = w.WriteString(s.value.String()) + n += int64(m) + if err != nil { + return + } + + return +} + +// Strings +type StringsField struct { + key []byte + values []string +} + +func Strings(key string, values []string) Field { + return &StringsField{ + key: []byte(key), + values: values, + } +} + +func (s *StringsField) WriteTo(w *bufio.Writer) (n int64, err error) { + var m int + + m, err = w.Write(s.key) + n += int64(m) + if err != nil { + return + } + + err = w.WriteByte('=') + n += 1 + if err != nil { + return + } + + err = w.WriteByte('[') + n += 1 + if err != nil { + return + } + + for i, value := range s.values { + if i != 0 { + // TODO: do we want spaces here? + err = w.WriteByte(',') + n += 1 + if err != nil { + return + } + } + + // TODO: properly escape + m, err = w.WriteString(value) + n += int64(m) + if err != nil { + return + } + } + + err = w.WriteByte(']') + n += 1 + if err != nil { + return + } + + return +} + +// Int +type IntField struct { + key []byte + value int +} + +func Int(key string, value int) Field { + return &IntField{ + key: []byte(key), + value: value, + } +} + +func (s *IntField) WriteTo(w *bufio.Writer) (n int64, err error) { + var m int + + m, err = w.Write(s.key) + n += int64(m) + if err != nil { + return + } + + err = w.WriteByte('=') + n += 1 + if err != nil { + return + } + + m, err = w.WriteString(strconv.Itoa(s.value)) + n += int64(m) + if err != nil { + return + } + + return +} + +// Int64 +type Int64Field struct { + key []byte + value int64 +} + +func Int64(key string, value int64) Field { + return &Int64Field{ + key: []byte(key), + value: value, + } +} + +func (s *Int64Field) WriteTo(w *bufio.Writer) (n int64, err error) { + var m int + + m, err = w.Write(s.key) + n += int64(m) + if err != nil { + return + } + + err = w.WriteByte('=') + n += 1 + if err != nil { + return + } + + m, err = w.WriteString(strconv.FormatInt(s.value, 10)) + n += int64(m) + if err != nil { + return + } + + return +} + +// Float64 +type Float64Field struct { + key []byte + value float64 +} + +func Float64(key string, value float64) Field { + return &Float64Field{ + key: []byte(key), + value: value, + } +} + +func (s *Float64Field) WriteTo(w *bufio.Writer) (n int64, err error) { + var m int + + m, err = w.Write(s.key) + n += int64(m) + if err != nil { + return + } + + err = w.WriteByte('=') + n += 1 + if err != nil { + return + } + + m, err = w.WriteString(strconv.FormatFloat(s.value, 'E', -1, 64)) + n += int64(m) + if err != nil { + return + } + + return +} + +// Bool +type BoolField struct { + key []byte + value bool +} + +func Bool(key string, value bool) Field { + return &BoolField{ + key: []byte(key), + value: value, + } +} + +func (s *BoolField) WriteTo(w *bufio.Writer) (n int64, err error) { + var m int + + m, err = w.Write(s.key) + n += int64(m) + if err != nil { + return + } + + err = w.WriteByte('=') + n += 1 + if err != nil { + return + } + + if s.value { + m, err = w.Write([]byte("true")) + n += int64(m) + if err != nil { + return + } + } else { + m, err = w.Write([]byte("false")) + n += int64(m) + if err != nil { + return + } + } + + return +} + +// Error +type ErrorField struct { + err error +} + +func Error(err error) Field { + return &ErrorField{ + err: err, + } +} + +func (s *ErrorField) WriteTo(w *bufio.Writer) (n int64, err error) { + var m int + + m, err = w.Write([]byte("err")) + n += int64(m) + if err != nil { + return + } + + err = w.WriteByte('=') + n += 1 + if err != nil { + return + } + + // TODO: properly escape? + m, err = w.WriteString(s.err.Error()) + n += int64(m) + if err != nil { + return + } + + return +} + +// Time +type TimeField struct { + key []byte + value time.Time +} + +func Time(key string, value time.Time) Field { + return &TimeField{ + key: []byte(key), + value: value, + } +} + +func (s *TimeField) WriteTo(w *bufio.Writer) (n int64, err error) { + var m int + + m, err = w.Write([]byte("err")) + n += int64(m) + if err != nil { + return + } + + err = w.WriteByte('=') + n += 1 + if err != nil { + return + } + + // TODO: properly escape? + m, err = w.WriteString(s.value.String()) + n += int64(m) + if err != nil { + return + } + + return +} + +// Duration +type DurationField struct { + key []byte + value time.Duration +} + +func Duration(key string, value time.Duration) Field { + return &DurationField{ + key: []byte(key), + value: value, + } +} + +func (s *DurationField) WriteTo(w *bufio.Writer) (n int64, err error) { + var m int + + m, err = w.Write([]byte("err")) + n += int64(m) + if err != nil { + return + } + + err = w.WriteByte('=') + n += 1 + if err != nil { + return + } + + // TODO: properly escape? + m, err = w.WriteString(s.value.String()) + n += int64(m) + if err != nil { + return + } + + return +} diff --git a/services/diagnostic/internal/log/log.go b/services/diagnostic/internal/log/log.go new file mode 100644 index 0000000000..4b2f74c212 --- /dev/null +++ b/services/diagnostic/internal/log/log.go @@ -0,0 +1,84 @@ +package log + +import ( + "bufio" + "io" + "strconv" + "sync" + "time" +) + +type Logger struct { + mu *sync.Mutex + context []Field + w *bufio.Writer +} + +func NewLogger(w io.Writer) *Logger { + var mu sync.Mutex + return &Logger{ + mu: &mu, + w: bufio.NewWriter(w), + } +} + +func (l *Logger) With(ctx ...Field) *Logger { + l.mu.Lock() + defer l.mu.Unlock() + return &Logger{ + mu: l.mu, + context: append(l.context, ctx...), + w: l.w, + } +} + +func (l *Logger) Error(msg string, ctx ...Field) { + l.Log(time.Now(), "error", msg, ctx) +} + +func (l *Logger) Debug(msg string, ctx ...Field) { + l.Log(time.Now(), "debug", msg, ctx) +} + +func (l *Logger) Warn(msg string, ctx ...Field) { + l.Log(time.Now(), "warn", msg, ctx) +} + +func (l *Logger) Info(msg string, ctx ...Field) { + l.Log(time.Now(), "info", msg, ctx) +} + +// TODO: actually care about errors? +func (l *Logger) Log(t time.Time, level string, msg string, ctx []Field) { + l.mu.Lock() + defer l.mu.Unlock() + + l.w.WriteString(strconv.FormatInt(t.Unix(), 10)) + l.w.WriteString(" ") + l.w.WriteString(level) + l.w.WriteString(" ") + l.w.WriteString(msg) + l.w.WriteString(" ") + + for i, f := range l.context { + if i != 0 { + l.w.WriteByte(' ') + } + f.WriteTo(l.w) + } + + if len(l.context) != 0 { + l.w.WriteByte(' ') + } + + for i, f := range ctx { + if i != 0 { + l.w.WriteByte(' ') + } + f.WriteTo(l.w) + } + + l.w.WriteByte('\n') + + l.w.Flush() +} diff --git a/services/diagnostic/service.go b/services/diagnostic/service.go index 497037f1dc..507cd39a53 100644 --- a/services/diagnostic/service.go +++ b/services/diagnostic/service.go @@ -10,8 +10,8 @@ import ( "sync" //"github.com/influxdata/kapacitor/server" + klog "github.com/influxdata/kapacitor/services/diagnostic/internal/log" - "go.uber.org/zap" "go.uber.org/zap/zapcore" ) @@ -25,7 +25,8 @@ func (c *nopCloser) Close() error { return nil } type Service struct { c Config - logger *zap.Logger + //logger *zap.Logger + logger *klog.Logger f io.WriteCloser stdout io.Writer @@ -78,11 +79,11 @@ func (s *Service) Open() error { s.level = s.c.Level s.mu.Unlock() - p := zap.LevelEnablerFunc(func(lvl zapcore.Level) bool { - s.mu.RLock() - defer s.mu.RUnlock() - return lvl >= zapcoreLevelFromName(s.level) - }) + ///p := zap.LevelEnablerFunc(func(lvl zapcore.Level) bool { + /// s.mu.RLock() + /// defer s.mu.RUnlock() + /// return lvl >= zapcoreLevelFromName(s.level) + ///}) switch s.c.File { case "STDERR": @@ -105,15 +106,15 @@ func (s *Service) Open() error { s.f = f } - out := zapcore.AddSync(s.f) - encConfig := zap.NewProductionEncoderConfig() - encConfig.EncodeTime = zapcore.EpochNanosTimeEncoder - consoleEnc := zapcore.NewConsoleEncoder(encConfig) - core := zapcore.NewTee( - zapcore.NewCore(consoleEnc, out, p), - ) - l := zap.New(core) - s.logger = l + //out := zapcore.AddSync(s.f) + //encConfig := zap.NewProductionEncoderConfig() + //encConfig.EncodeTime = zapcore.EpochNanosTimeEncoder + //consoleEnc := zapcore.NewConsoleEncoder(encConfig) + //core := zapcore.NewTee( + // zapcore.NewCore(consoleEnc, out, p), + //) + //l := zap.New(core) + s.logger = klog.NewLogger(s.f) return nil } @@ -126,271 +127,271 @@ func (s *Service) Close() error { func (s *Service) NewVictorOpsHandler() *VictorOpsHandler { return &VictorOpsHandler{ - l: s.logger.With(zap.String("service", "victorops")), + l: s.logger.With(klog.String("service", "victorops")), } } func (s *Service) NewSlackHandler() *SlackHandler { return &SlackHandler{ - l: s.logger.With(zap.String("service", "slack")), + l: s.logger.With(klog.String("service", "slack")), } } func (s *Service) NewTaskStoreHandler() *TaskStoreHandler { return &TaskStoreHandler{ - l: s.logger.With(zap.String("service", "task_store")), + l: s.logger.With(klog.String("service", "task_store")), } } func (s *Service) NewReportingHandler() *ReportingHandler { return &ReportingHandler{ - l: s.logger.With(zap.String("service", "reporting")), + l: s.logger.With(klog.String("service", "reporting")), } } func (s *Service) NewStorageHandler() *StorageHandler { return &StorageHandler{ - l: s.logger.With(zap.String("service", "storage")), + l: s.logger.With(klog.String("service", "storage")), } } func (s *Service) NewHTTPDHandler() *HTTPDHandler { return &HTTPDHandler{ - l: s.logger.With(zap.String("service", "http")), + l: s.logger.With(klog.String("service", "http")), } } func (s *Service) NewAlertaHandler() *AlertaHandler { return &AlertaHandler{ - l: s.logger.With(zap.String("service", "alerta")), + l: s.logger.With(klog.String("service", "alerta")), } } func (s *Service) NewKapacitorHandler() *KapacitorHandler { return &KapacitorHandler{ - l: s.logger.With(zap.String("service", "kapacitor")), // TODO: what here + l: s.logger.With(klog.String("service", "kapacitor")), // TODO: what here } } func (s *Service) NewAlertServiceHandler() *AlertServiceHandler { return &AlertServiceHandler{ - l: s.logger.With(zap.String("service", "alert")), + l: s.logger.With(klog.String("service", "alert")), } } func (s *Service) NewHipChatHandler() *HipChatHandler { return &HipChatHandler{ - l: s.logger.With(zap.String("service", "hipchat")), + l: s.logger.With(klog.String("service", "hipchat")), } } func (s *Service) NewPagerDutyHandler() *PagerDutyHandler { return &PagerDutyHandler{ - l: s.logger.With(zap.String("service", "pagerduty")), + l: s.logger.With(klog.String("service", "pagerduty")), } } func (s *Service) NewSMTPHandler() *SMTPHandler { return &SMTPHandler{ - l: s.logger.With(zap.String("service", "smtp")), + l: s.logger.With(klog.String("service", "smtp")), } } func (s *Service) NewUDFServiceHandler() *UDFServiceHandler { return &UDFServiceHandler{ - l: s.logger.With(zap.String("service", "udf")), + l: s.logger.With(klog.String("service", "udf")), } } func (s *Service) NewOpsGenieHandler() *OpsGenieHandler { return &OpsGenieHandler{ - l: s.logger.With(zap.String("service", "opsgenie")), + l: s.logger.With(klog.String("service", "opsgenie")), } } func (s *Service) NewPushoverHandler() *PushoverHandler { return &PushoverHandler{ - l: s.logger.With(zap.String("service", "pushover")), + l: s.logger.With(klog.String("service", "pushover")), } } func (s *Service) NewHTTPPostHandler() *HTTPPostHandler { return &HTTPPostHandler{ - l: s.logger.With(zap.String("service", "httppost")), + l: s.logger.With(klog.String("service", "httppost")), } } func (s *Service) NewSensuHandler() *SensuHandler { return &SensuHandler{ - l: s.logger.With(zap.String("service", "sensu")), + l: s.logger.With(klog.String("service", "sensu")), } } func (s *Service) NewSNMPTrapHandler() *SNMPTrapHandler { return &SNMPTrapHandler{ - l: s.logger.With(zap.String("service", "snmp")), + l: s.logger.With(klog.String("service", "snmp")), } } func (s *Service) NewTelegramHandler() *TelegramHandler { return &TelegramHandler{ - l: s.logger.With(zap.String("service", "telegram")), + l: s.logger.With(klog.String("service", "telegram")), } } func (s *Service) NewMQTTHandler() *MQTTHandler { return &MQTTHandler{ - l: s.logger.With(zap.String("service", "mqtt")), + l: s.logger.With(klog.String("service", "mqtt")), } } func (s *Service) NewTalkHandler() *TalkHandler { return &TalkHandler{ - l: s.logger.With(zap.String("service", "talk")), + l: s.logger.With(klog.String("service", "talk")), } } func (s *Service) NewConfigOverrideHandler() *ConfigOverrideHandler { return &ConfigOverrideHandler{ - l: s.logger.With(zap.String("service", "config-override")), + l: s.logger.With(klog.String("service", "config-override")), } } func (s *Service) NewServerHandler() *ServerHandler { return &ServerHandler{ // TODO: what to make key here - l: s.logger.With(zap.String("source", "srv")), + l: s.logger.With(klog.String("source", "srv")), } } func (s *Service) NewReplayHandler() *ReplayHandler { return &ReplayHandler{ - l: s.logger.With(zap.String("service", "replay")), + l: s.logger.With(klog.String("service", "replay")), } } func (s *Service) NewK8sHandler() *K8sHandler { return &K8sHandler{ - l: s.logger.With(zap.String("service", "kubernetes")), + l: s.logger.With(klog.String("service", "kubernetes")), } } func (s *Service) NewSwarmHandler() *SwarmHandler { return &SwarmHandler{ - l: s.logger.With(zap.String("service", "swarm")), + l: s.logger.With(klog.String("service", "swarm")), } } func (s *Service) NewDeadmanHandler() *DeadmanHandler { return &DeadmanHandler{ - l: s.logger.With(zap.String("service", "deadman")), + l: s.logger.With(klog.String("service", "deadman")), } } func (s *Service) NewNoAuthHandler() *NoAuthHandler { return &NoAuthHandler{ - l: s.logger.With(zap.String("service", "noauth")), + l: s.logger.With(klog.String("service", "noauth")), } } func (s *Service) NewStatsHandler() *StatsHandler { return &StatsHandler{ - l: s.logger.With(zap.String("service", "stats")), + l: s.logger.With(klog.String("service", "stats")), } } func (s *Service) NewUDPHandler() *UDPHandler { return &UDPHandler{ - l: s.logger.With(zap.String("service", "udp")), + l: s.logger.With(klog.String("service", "udp")), } } func (s *Service) NewInfluxDBHandler() *InfluxDBHandler { return &InfluxDBHandler{ - l: s.logger.With(zap.String("service", "influxdb")), + l: s.logger.With(klog.String("service", "influxdb")), } } func (s *Service) NewScraperHandler() *ScraperHandler { return &ScraperHandler{ - l: s.logger.With(zap.String("service", "scraper")), + l: s.logger.With(klog.String("service", "scraper")), buf: bytes.NewBuffer(nil), } } func (s *Service) NewAzureHandler() *ScraperHandler { return &ScraperHandler{ - l: s.logger.With(zap.String("service", "azure")), + l: s.logger.With(klog.String("service", "azure")), buf: bytes.NewBuffer(nil), } } func (s *Service) NewConsulHandler() *ScraperHandler { return &ScraperHandler{ - l: s.logger.With(zap.String("service", "consul")), + l: s.logger.With(klog.String("service", "consul")), buf: bytes.NewBuffer(nil), } } func (s *Service) NewDNSHandler() *ScraperHandler { return &ScraperHandler{ - l: s.logger.With(zap.String("service", "dns")), + l: s.logger.With(klog.String("service", "dns")), buf: bytes.NewBuffer(nil), } } func (s *Service) NewEC2Handler() *ScraperHandler { return &ScraperHandler{ - l: s.logger.With(zap.String("service", "ec2")), + l: s.logger.With(klog.String("service", "ec2")), buf: bytes.NewBuffer(nil), } } func (s *Service) NewFileDiscoveryHandler() *ScraperHandler { return &ScraperHandler{ - l: s.logger.With(zap.String("service", "file-discovery")), + l: s.logger.With(klog.String("service", "file-discovery")), buf: bytes.NewBuffer(nil), } } func (s *Service) NewGCEHandler() *ScraperHandler { return &ScraperHandler{ - l: s.logger.With(zap.String("service", "gce")), + l: s.logger.With(klog.String("service", "gce")), buf: bytes.NewBuffer(nil), } } func (s *Service) NewMarathonHandler() *ScraperHandler { return &ScraperHandler{ - l: s.logger.With(zap.String("service", "marathon")), + l: s.logger.With(klog.String("service", "marathon")), buf: bytes.NewBuffer(nil), } } func (s *Service) NewNerveHandler() *ScraperHandler { return &ScraperHandler{ - l: s.logger.With(zap.String("service", "nerve")), + l: s.logger.With(klog.String("service", "nerve")), buf: bytes.NewBuffer(nil), } } func (s *Service) NewServersetHandler() *ScraperHandler { return &ScraperHandler{ - l: s.logger.With(zap.String("service", "serverset")), + l: s.logger.With(klog.String("service", "serverset")), buf: bytes.NewBuffer(nil), } } func (s *Service) NewStaticDiscoveryHandler() *ScraperHandler { return &ScraperHandler{ - l: s.logger.With(zap.String("service", "static-discovery")), + l: s.logger.With(klog.String("service", "static-discovery")), buf: bytes.NewBuffer(nil), } } func (s *Service) NewTritonHandler() *ScraperHandler { return &ScraperHandler{ - l: s.logger.With(zap.String("service", "triton")), + l: s.logger.With(klog.String("service", "triton")), buf: bytes.NewBuffer(nil), } } @@ -416,13 +417,13 @@ func (s *Service) NewStaticLevelHandler(level string, service string) (*StaticLe } return &StaticLevelHandler{ - l: s.logger.With(zap.String("service", service)), + l: s.logger.With(klog.String("service", service)), level: ll, }, nil } func (s *Service) NewCmdHandler() *CmdHandler { return &CmdHandler{ - l: s.logger.With(zap.String("service", "run")), + l: s.logger.With(klog.String("service", "run")), } }