Skip to content

Commit

Permalink
Give logrus.Hook implementation information about task and subtask (#…
Browse files Browse the repository at this point in the history
…6313)

* add logrus.Logger return type on WithEventContext()

* give hook information about task and subtask

* linters
  • Loading branch information
MarlonGamez authored Jul 28, 2021
1 parent e62f675 commit 27c3822
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cmd/skaffold/app/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
18 changes: 13 additions & 5 deletions pkg/skaffold/event/v2/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down

0 comments on commit 27c3822

Please sign in to comment.