Report errors by setting raw_output when it's error level (#645)

This solves #643 by setting the "raw_output" entry attribute when the log level is error.  This results in the log line being shipped to the Gitea UI.

Reviewed-on: https://gitea.com/gitea/act_runner/pulls/645
Reviewed-by: Zettat123 <zettat123@noreply.gitea.com>
Co-authored-by: Pablo Carranza <pcarranza@gmail.com>
Co-committed-by: Pablo Carranza <pcarranza@gmail.com>
This commit is contained in:
Pablo Carranza
2025-06-05 17:53:13 +00:00
committed by Lunny Xiao
parent 5302c25feb
commit 6a9a447f86
2 changed files with 39 additions and 26 deletions

View File

@ -160,24 +160,7 @@ type daemonArgs struct {
// initLogging setup the global logrus logger. // initLogging setup the global logrus logger.
func initLogging(cfg *config.Config) { func initLogging(cfg *config.Config) {
isTerm := isatty.IsTerminal(os.Stdout.Fd()) callPrettyfier := func(f *runtime.Frame) (string, string) {
format := &log.TextFormatter{
DisableColors: !isTerm,
FullTimestamp: true,
}
log.SetFormatter(format)
if l := cfg.Log.Level; l != "" {
level, err := log.ParseLevel(l)
if err != nil {
log.WithError(err).
Errorf("invalid log level: %q", l)
}
// debug level
if level == log.DebugLevel {
log.SetReportCaller(true)
format.CallerPrettyfier = func(f *runtime.Frame) (string, string) {
// get function name // get function name
s := strings.Split(f.Function, ".") s := strings.Split(f.Function, ".")
funcname := "[" + s[len(s)-1] + "]" funcname := "[" + s[len(s)-1] + "]"
@ -186,15 +169,39 @@ func initLogging(cfg *config.Config) {
filename = "[" + filename + ":" + strconv.Itoa(f.Line) + "]" filename = "[" + filename + ":" + strconv.Itoa(f.Line) + "]"
return funcname, filename return funcname, filename
} }
isTerm := isatty.IsTerminal(os.Stdout.Fd())
format := &log.TextFormatter{
DisableColors: !isTerm,
FullTimestamp: true,
CallerPrettyfier: callPrettyfier,
}
log.SetFormatter(format) log.SetFormatter(format)
l := cfg.Log.Level
if l == "" {
log.Infof("Log level not set, sticking to info")
return
}
level, err := log.ParseLevel(l)
if err != nil {
log.WithError(err).
Errorf("invalid log level: %q", l)
}
// debug level
switch level {
case log.DebugLevel, log.TraceLevel:
log.SetReportCaller(true) // Only in debug or trace because it takes a performance toll
log.Infof("Log level %s requested, setting up report caller for further debugging", level)
} }
if log.GetLevel() != level { if log.GetLevel() != level {
log.Infof("log level changed to %v", level) log.Infof("log level set to %v", level)
log.SetLevel(level) log.SetLevel(level)
} }
} }
}
var commonSocketPaths = []string{ var commonSocketPaths = []string{
"/var/run/docker.sock", "/var/run/docker.sock",

View File

@ -143,6 +143,12 @@ func (r *Reporter) Fire(entry *log.Entry) error {
if step.StartedAt == nil { if step.StartedAt == nil {
step.StartedAt = timestamppb.New(timestamp) step.StartedAt = timestamppb.New(timestamp)
} }
// Force reporting log errors as raw output to prevent silent failures
if entry.Level == log.ErrorLevel {
entry.Data["raw_output"] = true
}
if v, ok := entry.Data["raw_output"]; ok { if v, ok := entry.Data["raw_output"]; ok {
if rawOutput, ok := v.(bool); ok && rawOutput { if rawOutput, ok := v.(bool); ok && rawOutput {
if row := r.parseLogRow(entry); row != nil { if row := r.parseLogRow(entry); row != nil {