From 603cf568780752efbe587dd50825b2ee5c3013ae Mon Sep 17 00:00:00 2001 From: Markus Wolf Date: Sat, 13 Nov 2021 00:20:45 +0100 Subject: [PATCH] feat: allow existing logger from context (#859) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We should reuse an existing context logger if available. This will allow test to setup act with a null logger to assert log messages. Co-authored-by: Björn Brauer Co-authored-by: Björn Brauer --- pkg/runner/logger.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/runner/logger.go b/pkg/runner/logger.go index 8464801..5819a50 100644 --- a/pkg/runner/logger.go +++ b/pkg/runner/logger.go @@ -47,7 +47,14 @@ func WithJobLogger(ctx context.Context, jobName string, secrets map[string]strin formatter.insecureSecrets = insecureSecrets nextColor++ - logger := logrus.New() + var logger *logrus.Logger + fieldLogger := common.Logger(ctx) + if fieldLogger != nil { + logger = fieldLogger.(*logrus.Logger) + } + if logger == nil { + logger = logrus.New() + } logger.SetFormatter(formatter) logger.SetOutput(os.Stdout) logger.SetLevel(logrus.GetLevel())