Cherry-pick gitea act_runner #543
From: 1735b26e66
Don't log job output when debug logging is not enabled
We wanted the ability to disable outputting the logs from the individual job to the console. This changes the logging so that job logs are only output to the console whenever debug logging is enabled in `act_runner`, while still allowing the `Reporter` to receive these logs and forward them to Gitea when debug logging is not enabled.
Signed-off-by: Kwonunn <kwonunnx@gmail.com>
This commit is contained in:
parent
b76cd576ef
commit
6c9959d7a9
2 changed files with 28 additions and 0 deletions
24
internal/app/run/logging.go
Normal file
24
internal/app/run/logging.go
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
// Copyright 2024 The Gitea Authors. All rights reserved.
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
package run
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
)
|
||||||
|
|
||||||
|
// NullLogger is used to create a new JobLogger to discard logs. This
|
||||||
|
// will prevent these logs from being logged to the stdout, but
|
||||||
|
// forward them to the Reporter via its hook.
|
||||||
|
type NullLogger struct{}
|
||||||
|
|
||||||
|
// WithJobLogger creates a new logrus.Logger that will discard all logs.
|
||||||
|
func (n NullLogger) WithJobLogger() *log.Logger {
|
||||||
|
logger := log.New()
|
||||||
|
logger.SetOutput(io.Discard)
|
||||||
|
logger.SetLevel(log.TraceLevel)
|
||||||
|
|
||||||
|
return logger
|
||||||
|
}
|
|
@ -252,6 +252,10 @@ func (r *Runner) run(ctx context.Context, task *runnerv1.Task, reporter *report.
|
||||||
// add logger recorders
|
// add logger recorders
|
||||||
ctx = common.WithLoggerHook(ctx, reporter)
|
ctx = common.WithLoggerHook(ctx, reporter)
|
||||||
|
|
||||||
|
if !log.IsLevelEnabled(log.DebugLevel) {
|
||||||
|
ctx = runner.WithJobLoggerFactory(ctx, NullLogger{})
|
||||||
|
}
|
||||||
|
|
||||||
execErr := executor(ctx)
|
execErr := executor(ctx)
|
||||||
reporter.SetOutputs(job.Outputs)
|
reporter.SetOutputs(job.Outputs)
|
||||||
return execErr
|
return execErr
|
||||||
|
|
Loading…
Reference in a new issue