diff --git a/internal/app/run/logging.go b/internal/app/run/logging.go new file mode 100644 index 0000000..d0e6d1c --- /dev/null +++ b/internal/app/run/logging.go @@ -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 +} diff --git a/internal/app/run/runner.go b/internal/app/run/runner.go index e774786..9eaf37e 100644 --- a/internal/app/run/runner.go +++ b/internal/app/run/runner.go @@ -252,6 +252,10 @@ func (r *Runner) run(ctx context.Context, task *runnerv1.Task, reporter *report. // add logger recorders ctx = common.WithLoggerHook(ctx, reporter) + if !log.IsLevelEnabled(log.DebugLevel) { + ctx = runner.WithJobLoggerFactory(ctx, NullLogger{}) + } + execErr := executor(ctx) reporter.SetOutputs(job.Outputs) return execErr