mirror of
https://github.com/ossf/scorecard.git
synced 2024-09-11 08:55:27 +03:00
🌱 cron: structured logging (#3167)
* Structured logging for cron Signed-off-by: Raghav Kaul <raghavkaul@google.com> * also update scorecard worker logger Signed-off-by: Raghav Kaul <raghavkaul@google.com> * address pr comments * set json fields * docs link --------- Signed-off-by: Raghav Kaul <raghavkaul@google.com>
This commit is contained in:
parent
2aa9887f13
commit
eb941e3964
@ -118,7 +118,7 @@ func newScorecardWorker() (*ScorecardWorker, error) {
|
||||
}
|
||||
|
||||
sw.ctx = context.Background()
|
||||
sw.logger = log.NewLogger(log.InfoLevel)
|
||||
sw.logger = log.NewCronLogger(log.InfoLevel)
|
||||
sw.githubClient = githubrepo.CreateGithubRepoClient(sw.ctx, sw.logger)
|
||||
// TODO(raghavkaul): Read GitLab auth token from environment
|
||||
if sw.gitlabClient, err = gitlabrepo.CreateGitlabClient(sw.ctx, "https://gitlab.com"); err != nil {
|
||||
|
@ -74,7 +74,7 @@ func (wl *WorkLoop) Run() error {
|
||||
return fmt.Errorf("config.GetResultDataBucketURL: %w", err)
|
||||
}
|
||||
|
||||
logger := log.NewLogger(log.InfoLevel)
|
||||
logger := log.NewCronLogger(log.InfoLevel)
|
||||
|
||||
for {
|
||||
req, err := subscriber.SynchronousPull()
|
||||
|
17
log/log.go
17
log/log.go
@ -41,6 +41,23 @@ func NewLogger(logLevel Level) *Logger {
|
||||
return NewLogrusLogger(logrusLog)
|
||||
}
|
||||
|
||||
// NewCronLogger creates an instance of *Logger.
|
||||
func NewCronLogger(logLevel Level) *Logger {
|
||||
logrusLog := logrus.New()
|
||||
|
||||
// for stackdriver, see: https://cloud.google.com/logging/docs/structured-logging#special-payload-fields
|
||||
logrusLog.SetFormatter(&logrus.JSONFormatter{FieldMap: logrus.FieldMap{
|
||||
logrus.FieldKeyLevel: "severity",
|
||||
logrus.FieldKeyMsg: "message",
|
||||
}})
|
||||
|
||||
// Set log level from logrus
|
||||
logrusLevel := parseLogrusLevel(logLevel)
|
||||
logrusLog.SetLevel(logrusLevel)
|
||||
|
||||
return NewLogrusLogger(logrusLog)
|
||||
}
|
||||
|
||||
// NewLogrusLogger creates an instance of *Logger backed by the supplied
|
||||
// logrusLog instance.
|
||||
func NewLogrusLogger(logrusLog *logrus.Logger) *Logger {
|
||||
|
Loading…
Reference in New Issue
Block a user