diff --git a/checks/binary_artifact_test.go b/checks/binary_artifact_test.go index a64f1502f174..e4bb9ffda241 100644 --- a/checks/binary_artifact_test.go +++ b/checks/binary_artifact_test.go @@ -22,7 +22,6 @@ import ( "github.com/golang/mock/gomock" "github.com/ossf/scorecard/v4/checker" - "github.com/ossf/scorecard/v4/clients/githubrepo" "github.com/ossf/scorecard/v4/clients/localdir" "github.com/ossf/scorecard/v4/log" scut "github.com/ossf/scorecard/v4/utests" @@ -60,10 +59,7 @@ func TestBinaryArtifacts(t *testing.T) { t.Run(tt.name, func(t *testing.T) { t.Parallel() - logger, err := githubrepo.NewLogger(log.DebugLevel) - if err != nil { - t.Errorf("githubrepo.NewLogger: %v", err) - } + logger := log.NewLogger(log.DebugLevel) ctrl := gomock.NewController(t) repo, err := localdir.MakeLocalDirRepo(tt.inputFolder) diff --git a/checks/license_test.go b/checks/license_test.go index ef233bb51389..c126f5a73a26 100644 --- a/checks/license_test.go +++ b/checks/license_test.go @@ -22,7 +22,6 @@ import ( "github.com/golang/mock/gomock" "github.com/ossf/scorecard/v4/checker" - "github.com/ossf/scorecard/v4/clients/githubrepo" "github.com/ossf/scorecard/v4/clients/localdir" "github.com/ossf/scorecard/v4/log" scut "github.com/ossf/scorecard/v4/utests" @@ -142,10 +141,7 @@ func TestLicenseFileSubdirectory(t *testing.T) { t.Run(tt.name, func(t *testing.T) { t.Parallel() - logger, err := githubrepo.NewLogger(log.DebugLevel) - if err != nil { - t.Errorf("githubrepo.NewLogger: %v", err) - } + logger := log.NewLogger(log.DebugLevel) ctrl := gomock.NewController(t) repo, err := localdir.MakeLocalDirRepo(tt.inputFolder) diff --git a/checks/raw/security_policy.go b/checks/raw/security_policy.go index 36350637461b..fbcdf9ecdaeb 100644 --- a/checks/raw/security_policy.go +++ b/checks/raw/security_policy.go @@ -16,7 +16,6 @@ package raw import ( "errors" - "fmt" "strings" "github.com/ossf/scorecard/v4/checker" @@ -70,10 +69,7 @@ func SecurityPolicy(c *checker.CheckRequest) (checker.SecurityPolicyData, error) } // https://docs.github.com/en/github/building-a-strong-community/creating-a-default-community-health-file. - logger, err := githubrepo.NewLogger(log.InfoLevel) - if err != nil { - return checker.SecurityPolicyData{}, fmt.Errorf("%w", err) - } + logger := log.NewLogger(log.InfoLevel) dotGitHub := &checker.CheckRequest{ Ctx: c.Ctx, Dlogger: c.Dlogger, diff --git a/clients/githubrepo/client.go b/clients/githubrepo/client.go index 6d53e6949be4..e21f3ca85f83 100644 --- a/clients/githubrepo/client.go +++ b/clients/githubrepo/client.go @@ -219,18 +219,6 @@ func CreateGithubRepoClient(ctx context.Context, logger *log.Logger) clients.Rep } } -// NewLogger creates an instance of *log.Logger. -// TODO(log): Consider removing this function, as it only serves to wrap -// `log.NewLogger` for convenience. -func NewLogger(logLevel log.Level) (*log.Logger, error) { - logger, err := log.NewLogger(logLevel) - if err != nil { - return nil, fmt.Errorf("creating GitHub repo client logger: %w", err) - } - - return logger, nil -} - // CreateOssFuzzRepoClient returns a RepoClient implementation // intialized to `google/oss-fuzz` GitHub repository. func CreateOssFuzzRepoClient(ctx context.Context, logger *log.Logger) (clients.RepoClient, error) { diff --git a/clients/githubrepo/roundtripper/rate_limit.go b/clients/githubrepo/roundtripper/rate_limit.go index b664349c7209..8fb55af3f4b6 100644 --- a/clients/githubrepo/roundtripper/rate_limit.go +++ b/clients/githubrepo/roundtripper/rate_limit.go @@ -63,7 +63,7 @@ func (gh *rateLimitTransport) RoundTrip(r *http.Request) (*http.Response, error) // Retry time.Sleep(duration) // TODO(log): Previously Warn. Consider logging an error here. - gh.logger.Info(fmt.Sprintf("Rate limit exceeded. Retrying...")) + gh.logger.Info("Rate limit exceeded. Retrying...") return gh.RoundTrip(r) } diff --git a/clients/localdir/client_test.go b/clients/localdir/client_test.go index c57e6f88fd7f..f4fbb64c6bce 100644 --- a/clients/localdir/client_test.go +++ b/clients/localdir/client_test.go @@ -24,7 +24,6 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - "github.com/ossf/scorecard/v4/clients/githubrepo" "github.com/ossf/scorecard/v4/log" ) @@ -63,10 +62,7 @@ func TestClient_CreationAndCaching(t *testing.T) { t.Parallel() ctx := context.Background() - logger, err := githubrepo.NewLogger(log.DebugLevel) - if err != nil { - t.Errorf("githubrepo.NewLogger: %v", err) - } + logger := log.NewLogger(log.DebugLevel) // Create repo. repo, err := MakeLocalDirRepo(tt.inputFolder) diff --git a/cmd/root.go b/cmd/root.go index d0a8b137afd9..c38ebee4d7fb 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -188,11 +188,7 @@ func scorecardCmd(cmd *cobra.Command, args []string) { } ctx := context.Background() - logger, err := githubrepo.NewLogger(sclog.Level(logLevel)) - if err != nil { - log.Panic(err) - } - + logger := sclog.NewLogger(sclog.Level(logLevel)) repoURI, repoClient, ossFuzzRepoClient, ciiClient, vulnsClient, repoType, err := getRepoAccessors(ctx, uri, logger) if err != nil { log.Panic(err) diff --git a/cmd/serve.go b/cmd/serve.go index af681bed8b95..9d7e9c57dfaa 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -17,7 +17,6 @@ package cmd import ( "fmt" "html/template" - "log" "net/http" "os" "strings" @@ -27,7 +26,7 @@ import ( "github.com/ossf/scorecard/v4/checks" "github.com/ossf/scorecard/v4/clients" "github.com/ossf/scorecard/v4/clients/githubrepo" - sclog "github.com/ossf/scorecard/v4/log" + "github.com/ossf/scorecard/v4/log" "github.com/ossf/scorecard/v4/pkg" ) @@ -41,11 +40,7 @@ var serveCmd = &cobra.Command{ Short: "Serve the scorecard program over http", Long: ``, Run: func(cmd *cobra.Command, args []string) { - logger, err := githubrepo.NewLogger(sclog.Level(logLevel)) - if err != nil { - // TODO(log): Drop stdlib log - log.Fatalf("unable to construct logger: %v", err) - } + logger := log.NewLogger(log.Level(logLevel)) t, err := template.New("webpage").Parse(tpl) if err != nil { @@ -83,7 +78,7 @@ var serveCmd = &cobra.Command{ } if r.Header.Get("Content-Type") == "application/json" { - if err := repoResult.AsJSON(showDetails, sclog.Level(logLevel), rw); err != nil { + if err := repoResult.AsJSON(showDetails, log.Level(logLevel), rw); err != nil { // TODO(log): Improve error message logger.Error(err, "") rw.WriteHeader(http.StatusInternalServerError) diff --git a/cron/worker/main.go b/cron/worker/main.go index 06bd6240e294..6c025d551a8a 100644 --- a/cron/worker/main.go +++ b/cron/worker/main.go @@ -187,10 +187,7 @@ func main() { panic(err) } - logger, err := githubrepo.NewLogger(log.InfoLevel) - if err != nil { - panic(err) - } + logger := log.NewLogger(log.InfoLevel) repoClient := githubrepo.CreateGithubRepoClient(ctx, logger) ciiClient := clients.BlobCIIBestPracticesClient(ciiDataBucketURL) ossFuzzRepoClient, err := githubrepo.CreateOssFuzzRepoClient(ctx, logger) diff --git a/e2e/e2e_suite_test.go b/e2e/e2e_suite_test.go index 820d02e43377..e1956afb7f5d 100644 --- a/e2e/e2e_suite_test.go +++ b/e2e/e2e_suite_test.go @@ -21,7 +21,6 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - "github.com/ossf/scorecard/v4/clients/githubrepo" "github.com/ossf/scorecard/v4/log" ) @@ -41,8 +40,7 @@ var _ = BeforeSuite(func() { "GITHUB_AUTH_TOKEN env variable is not set.The GITHUB_AUTH_TOKEN env variable has to be set to run e2e test.") Expect(len(token)).ShouldNot(BeZero(), "Length of the GITHUB_AUTH_TOKEN env variable is zero.") - l, err := githubrepo.NewLogger(log.InfoLevel) - Expect(err).Should(BeNil()) + l := log.NewLogger(log.InfoLevel) logger = l }) diff --git a/go.mod b/go.mod index fd3baeef54da..06db646f0f4e 100644 --- a/go.mod +++ b/go.mod @@ -8,8 +8,10 @@ require ( cloud.google.com/go/pubsub v1.17.0 cloud.google.com/go/trace v0.1.0 // indirect contrib.go.opencensus.io/exporter/stackdriver v0.13.8 + github.com/bombsimon/logrusr/v2 v2.0.1 github.com/bradleyfalzon/ghinstallation/v2 v2.0.4 github.com/go-git/go-git/v5 v5.4.2 + github.com/go-logr/logr v1.2.2 github.com/golang/mock v1.6.0 github.com/google/go-cmp v0.5.7 github.com/google/go-containerregistry v0.8.0 @@ -22,6 +24,7 @@ require ( github.com/onsi/gomega v1.18.0 github.com/shurcooL/githubv4 v0.0.0-20201206200315-234843c633fa github.com/shurcooL/graphql v0.0.0-20200928012149-18c5c3165e3a // indirect + github.com/sirupsen/logrus v1.8.1 github.com/spf13/cobra v1.3.0 github.com/xeipuuv/gojsonschema v0.0.0-20180618132009-1d523034197f go.opencensus.io v0.23.0 @@ -34,11 +37,10 @@ require ( mvdan.cc/sh/v3 v3.4.2 ) +// TODO(go.mod): Is there a reason these deps are kept separately from the +// other `require`s? require ( - github.com/bombsimon/logrusr/v2 v2.0.1 - github.com/go-logr/logr v1.0.0 github.com/rhysd/actionlint v1.6.8 - github.com/sirupsen/logrus v1.8.1 gotest.tools v2.2.0+incompatible ) diff --git a/go.sum b/go.sum index 742f7c83e253..482e3c531107 100644 --- a/go.sum +++ b/go.sum @@ -585,8 +585,9 @@ github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9 github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas= github.com/go-logr/logr v0.2.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU= -github.com/go-logr/logr v1.0.0 h1:kH951GinvFVaQgy/ki/B3YYmQtRpExGigSJg6O8z5jo= github.com/go-logr/logr v1.0.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.2.2 h1:ahHml/yUpnlb96Rp8HCvtYVPY8ZYpxq3g7UYchIYwbs= +github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-ole/go-ole v1.2.1/go.mod h1:7FAglXiTm7HKlQRDeOQ6ZNUHidzCWXuZWq/1dTyBNF8= github.com/go-openapi/jsonpointer v0.0.0-20160704185906-46af16f9f7b1/go.mod h1:+35s3my2LFTysnkMfxsJBAMHj/DoqoB9knIWoYG/Vk0= github.com/go-openapi/jsonpointer v0.19.2/go.mod h1:3akKfEdA7DF1sugOqz1dVQHBcuDBPKZGEoHC/NkiQRg=