Skip to content

Commit

Permalink
log: Update references to log.Logger
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Augustus <[email protected]>
  • Loading branch information
justaugustus committed Jan 25, 2022
1 parent 0bdf07b commit f85ee75
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 57 deletions.
6 changes: 1 addition & 5 deletions checks/binary_artifact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 1 addition & 5 deletions checks/license_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 1 addition & 5 deletions checks/raw/security_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package raw

import (
"errors"
"fmt"
"strings"

"github.com/ossf/scorecard/v4/checker"
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 0 additions & 12 deletions clients/githubrepo/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion clients/githubrepo/roundtripper/rate_limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
6 changes: 1 addition & 5 deletions clients/localdir/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
Expand Down
6 changes: 1 addition & 5 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 3 additions & 8 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package cmd
import (
"fmt"
"html/template"
"log"
"net/http"
"os"
"strings"
Expand All @@ -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"
)

Expand All @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 1 addition & 4 deletions cron/worker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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
})

Expand Down
8 changes: 5 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
)

Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit f85ee75

Please sign in to comment.