Skip to content

Commit

Permalink
fix: move some function + add level in log (#5177)
Browse files Browse the repository at this point in the history
  • Loading branch information
sguiheux authored May 13, 2020
1 parent 21b845b commit 2fae99d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
21 changes: 20 additions & 1 deletion engine/cdn/cdn_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,26 @@ func (s *Service) handleWorkerLog(ctx context.Context, workerID string, sig inte
if !strings.HasSuffix(logs.Val, "\n") {
logs.Val += "\n"
}

var lvl string
switch m.Level {
case int32(hook.LOG_DEBUG):
lvl = "DEBUG"
case int32(hook.LOG_INFO):
lvl = "INFO"
case int32(hook.LOG_NOTICE):
lvl = "NOTICE"
case int32(hook.LOG_WARNING):
lvl = "WARN"
case int32(hook.LOG_ERR):
lvl = "ERROR"
case int32(hook.LOG_CRIT):
lvl = "CRITICAL"
case int32(hook.LOG_ALERT):
lvl = "ALERT"
case int32(hook.LOG_EMERG):
lvl = "EMERGENCY"
}
logs.Val = fmt.Sprintf("[%s] %s", lvl, logs.Val)
tx, err := s.Db.Begin()
if err != nil {
return sdk.WithStack(err)
Expand Down
2 changes: 1 addition & 1 deletion engine/cdn/cdn_log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func TestWorkerLog(t *testing.T) {
logs, err := workflow.LoadLogs(s.Db, dbj.ID)
require.NoError(t, err)
require.Len(t, logs, 1)
require.Equal(t, "this is my message\n", logs[0].Val)
require.Equal(t, "[ALERT] this is my message\n", logs[0].Val)
}

func TestServiceLog(t *testing.T) {
Expand Down
7 changes: 0 additions & 7 deletions engine/worker/internal/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@ import (
)

func (wk *CurrentWorker) sendLog(buildID int64, value string, stepOrder int, final bool) error {
if wk.currentJob.wJob == nil {
log.Error(wk.GetContext(), "unable to send log: %s", value)
return nil
}
if err := wk.Blur(&value); err != nil {
return err
}
now := time.Now()
l := sdk.NewLog(buildID, wk.currentJob.wJob.WorkflowNodeRunID, value, stepOrder)
if final {
Expand Down
10 changes: 10 additions & 0 deletions engine/worker/internal/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ func (wk *CurrentWorker) Parameters() []sdk.Parameter {
}

func (wk *CurrentWorker) SendLog(ctx context.Context, level workerruntime.Level, s string) {
if wk.currentJob.wJob == nil {
log.Error(wk.GetContext(), "unable to send log: %s. Job is nil", s)
return
}
if err := wk.Blur(&s); err != nil {
log.Error(wk.GetContext(), "unable to blur log: %v", err)
return
}

jobID, _ := workerruntime.JobID(ctx)
stepOrder, err := workerruntime.StepOrder(ctx)
if wk.logger.stepLogger == nil {
Expand All @@ -99,6 +108,7 @@ func (wk *CurrentWorker) SendLog(ctx context.Context, level workerruntime.Level,
}
return
}

var logLevel logrus.Level
switch level {
case workerruntime.LevelDebug:
Expand Down

0 comments on commit 2fae99d

Please sign in to comment.