secrets_cleanup.go 516 Bytes
Newer Older
1
package log
2 3

import (
4
	"github.com/sirupsen/logrus"
5 6 7 8 9 10 11

	"gitlab.com/gitlab-org/gitlab-runner/helpers/url"
)

type SecretsCleanupHook struct{}

func (s *SecretsCleanupHook) Levels() []logrus.Level {
12
	return logrus.AllLevels
13 14 15 16 17 18 19
}

func (s *SecretsCleanupHook) Fire(entry *logrus.Entry) error {
	entry.Message = url_helpers.ScrubSecrets(entry.Message)
	return nil
}

20 21 22 23 24 25
func AddSecretsCleanupLogHook(logger *logrus.Logger) {
	if logger == nil {
		logger = logrus.StandardLogger()
	}

	logger.AddHook(new(SecretsCleanupHook))
26
}