From 6c9959d7a96a7876f3c51f834f3a11d98eca621e Mon Sep 17 00:00:00 2001 From: Kwonunn Date: Mon, 28 Oct 2024 08:58:35 +0100 Subject: [PATCH 1/2] Cherry-pick gitea act_runner #543 From: https://gitea.com/gitea/act_runner/commit/1735b26e66f8e81c526204c128f1bcfd7f578906 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 --- internal/app/run/logging.go | 24 ++++++++++++++++++++++++ internal/app/run/runner.go | 4 ++++ 2 files changed, 28 insertions(+) create mode 100644 internal/app/run/logging.go 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 From 0ba115ba6789411868fa92ec882470bc3307b664 Mon Sep 17 00:00:00 2001 From: Kwonunn Date: Sun, 3 Nov 2024 15:10:54 +0100 Subject: [PATCH 2/2] Version bump and add release notes --- RELEASE-NOTES.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index f899d14..01fcf39 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -1,8 +1,9 @@ # Release Notes -## 4.1.0 +## 5.0.0 * [Add job_level logging option to config](https://code.forgejo.org/forgejo/runner/pulls/299) to make the logging level of jobs configurable. Change default from "trace" to "info". +* [Don't log job output when debug logging is not enabled](https://code.forgejo.org/forgejo/runner/pulls/303). This reduces the default amount of log output of the runner. ## 4.0.1