Skip to content

Commit 70bb851

Browse files
committed
feat(cli): add env var SEMAPHORE_LOG_LEVEL
1 parent 61f9418 commit 70bb851

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

cli/cmd/root.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,21 @@ Complete documentation is available at https://semaphoreui.com.`,
4141
return
4242
}
4343

44-
lvl, err := log.ParseLevel(persistentFlags.logLevel)
45-
if err != nil {
46-
log.Panic(err)
44+
lvl := log.InfoLevel
45+
var err error
46+
47+
if os.Getenv("SEMAPHORE_LOG_LEVEL") != "" {
48+
lvl, err = log.ParseLevel(os.Getenv("SEMAPHORE_LOG_LEVEL"))
49+
if err != nil {
50+
log.Panic(err)
51+
}
52+
}
53+
54+
if persistentFlags.logLevel != "" {
55+
lvl, err = log.ParseLevel(persistentFlags.logLevel)
56+
if err != nil {
57+
log.Panic(err)
58+
}
4759
}
4860

4961
log.SetLevel(lvl)

services/tasks/TaskRunner.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package tasks
33
import (
44
"encoding/json"
55
"errors"
6-
"github.com/semaphoreui/semaphore/services/tasks/hooks"
76
"github.com/semaphoreui/semaphore/pkg/tz"
7+
"github.com/semaphoreui/semaphore/services/tasks/hooks"
88
"os"
99
"strconv"
1010
"strings"
@@ -192,7 +192,11 @@ func (t *TaskRunner) run() {
192192
if t.job.IsKilled() {
193193
t.SetStatus(task_logger.TaskStoppedStatus)
194194
} else {
195-
log.WithError(err).Warn("Failed to run task")
195+
log.WithError(err).WithFields(log.Fields{
196+
"task_id": t.Task.ID,
197+
"context": "task_runner",
198+
"task_status": t.Task.Status,
199+
}).Warn("Failed to run task")
196200
t.Log("Failed to run task: " + err.Error())
197201
t.SetStatus(task_logger.TaskFailStatus)
198202
}

0 commit comments

Comments
 (0)