From 27c38228ab929ddaf2636637b43f17fda1686652 Mon Sep 17 00:00:00 2001 From: Marlon Gamez Date: Wed, 28 Jul 2021 11:24:33 -0700 Subject: [PATCH] Give `logrus.Hook` implementation information about task and subtask (#6313) * add logrus.Logger return type on WithEventContext() * give hook information about task and subtask * linters --- cmd/skaffold/app/cmd/cmd.go | 2 +- pkg/skaffold/event/v2/logger.go | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/cmd/skaffold/app/cmd/cmd.go b/cmd/skaffold/app/cmd/cmd.go index f6c21213399..149ff33da48 100644 --- a/cmd/skaffold/app/cmd/cmd.go +++ b/cmd/skaffold/app/cmd/cmd.go @@ -262,7 +262,7 @@ func setUpLogs(stdErr io.Writer, level string, timestamp bool) error { logrus.SetFormatter(&logrus.TextFormatter{ FullTimestamp: timestamp, }) - logrus.AddHook(event.NewLogHook()) + logrus.AddHook(event.NewLogHook(constants.DevLoop, event.SubtaskIDNone)) return nil } diff --git a/pkg/skaffold/event/v2/logger.go b/pkg/skaffold/event/v2/logger.go index b296f588a4a..d38e68a8cf1 100644 --- a/pkg/skaffold/event/v2/logger.go +++ b/pkg/skaffold/event/v2/logger.go @@ -59,10 +59,16 @@ func (ev *eventHandler) handleSkaffoldLogEvent(e *proto.SkaffoldLogEvent) { } // logHook is an implementation of logrus.Hook used to send SkaffoldLogEvents -type logHook struct{} +type logHook struct { + task constants.Phase + subtask string +} -func NewLogHook() logrus.Hook { - return logHook{} +func NewLogHook(task constants.Phase, subtask string) logrus.Hook { + return logHook{ + task: task, + subtask: subtask, + } } // Levels returns all levels as we want to send events for all levels @@ -81,8 +87,10 @@ func (h logHook) Levels() []logrus.Level { // Fire constructs a SkaffoldLogEvent and sends it to the event channel func (h logHook) Fire(entry *logrus.Entry) error { handler.handleSkaffoldLogEvent(&proto.SkaffoldLogEvent{ - Level: levelFromEntry(entry), - Message: entry.Message, + TaskId: fmt.Sprintf("%s-%d", h.task, handler.iteration), + SubtaskId: h.subtask, + Level: levelFromEntry(entry), + Message: entry.Message, }) return nil }