feat: allow existing logger from context (#859)

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 <bjoern.brauer@new-work.se>

Co-authored-by: Björn Brauer <bjoern.brauer@new-work.se>
This commit is contained in:
Markus Wolf 2021-11-13 00:20:45 +01:00 committed by GitHub
parent cd24df5727
commit 603cf56878
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 1 deletions

View File

@ -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())