From 2e895c147eb23b08cd935dcec3e974a0b452ba97 Mon Sep 17 00:00:00 2001 From: Haiyan Meng Date: Tue, 14 Jan 2020 15:50:35 -0800 Subject: [PATCH] Use log.Print* instead of fmt.Print* --- api/internal/crawl/cmd/crawler/crawler.go | 12 ++++++------ api/internal/crawl/cmd/log-parser/main.go | 1 + api/internal/crawl/crawler/crawler_test.go | 5 +++-- .../crawl/crawler/github/split_search_ranges_test.go | 3 ++- api/internal/crawl/doc/doc.go | 3 ++- api/internal/crawl/index/kustomize.go | 4 ++-- 6 files changed, 16 insertions(+), 12 deletions(-) diff --git a/api/internal/crawl/cmd/crawler/crawler.go b/api/internal/crawl/cmd/crawler/crawler.go index a5306dbfc..4a7883e54 100644 --- a/api/internal/crawl/cmd/crawler/crawler.go +++ b/api/internal/crawl/cmd/crawler/crawler.go @@ -75,7 +75,7 @@ func main() { githubToken := os.Getenv(githubAccessTokenVar) if githubToken == "" { - fmt.Printf("Must set the variable '%s' to make github requests.\n", + log.Printf("Must set the variable '%s' to make github requests.\n", githubAccessTokenVar) return } @@ -83,7 +83,7 @@ func main() { ctx := context.Background() idx, err := index.NewKustomizeIndex(ctx, *indexNamePtr) if err != nil { - fmt.Printf("Could not create an index: %v\n", err) + log.Printf("Could not create an index: %v\n", err) return } @@ -91,7 +91,7 @@ func main() { cache, err := redis.DialURL(cacheURL) clientCache := &http.Client{} if err != nil { - fmt.Printf("Error: redis could not make a connection: %v\n", err) + log.Printf("Error: redis could not make a connection: %v\n", err) } else { clientCache = httpclient.NewClient(cache) } @@ -112,10 +112,10 @@ func main() { case *doc.KustomizationDocument: switch mode { case index.Delete: - fmt.Println("Deleting: ", d) + log.Printf("Deleting: %v", d) return idx.Delete(d.ID()) default: - fmt.Println("Inserting: ", d) + log.Printf("Inserting: %v", d) return idx.Put(d.ID(), d) } default: @@ -168,7 +168,7 @@ func main() { } } if err := it.Err(); err != nil { - fmt.Printf("Error iterating: %v\n", err) + log.Fatalf("getSeedDocsFunc Error iterating: %v\n", err) } } diff --git a/api/internal/crawl/cmd/log-parser/main.go b/api/internal/crawl/cmd/log-parser/main.go index ac1a00f33..e442c8349 100644 --- a/api/internal/crawl/cmd/log-parser/main.go +++ b/api/internal/crawl/cmd/log-parser/main.go @@ -36,6 +36,7 @@ func main() { m := entry.(map[string]interface{}) if payload, ok := m["textPayload"]; ok { + // use fmt.Printf here instead of log.Printf to avoid the time and code location info the log package provides fmt.Printf("%s", payload) } else { log.Printf("the log entry does not have the `textPayload` field: %s\n", line) diff --git a/api/internal/crawl/crawler/crawler_test.go b/api/internal/crawl/crawler/crawler_test.go index 383e834a5..7dace4da6 100644 --- a/api/internal/crawl/crawler/crawler_test.go +++ b/api/internal/crawl/crawler/crawler_test.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "log" "reflect" "sort" "strings" @@ -110,7 +111,7 @@ func (s sortableDocs) Len() int { } func TestCrawlGithubRunner(t *testing.T) { - fmt.Println("testing CrawlGithubRunner") + log.Println("testing CrawlGithubRunner") tests := []struct { tc []Crawler errs []error @@ -216,7 +217,7 @@ func TestCrawlGithubRunner(t *testing.T) { } func TestCrawlFromSeed(t *testing.T) { - fmt.Println("testing CrawlFromSeed") + log.Println("testing CrawlFromSeed") tests := []struct { seed CrawlSeed diff --git a/api/internal/crawl/crawler/github/split_search_ranges_test.go b/api/internal/crawl/crawler/github/split_search_ranges_test.go index c175486e6..ad332388d 100644 --- a/api/internal/crawl/crawler/github/split_search_ranges_test.go +++ b/api/internal/crawl/crawler/github/split_search_ranges_test.go @@ -2,6 +2,7 @@ package github import ( "fmt" + "log" "reflect" "testing" ) @@ -11,7 +12,7 @@ type testCachedSearch struct { } func (c testCachedSearch) CountResults(upperBound uint64) (uint64, error) { - fmt.Printf("CountResults(%05x)\n", upperBound) + log.Printf("CountResults(%05x)\n", upperBound) count, ok := c.cache[upperBound] if !ok { return count, fmt.Errorf("cache not set at %x", upperBound) diff --git a/api/internal/crawl/doc/doc.go b/api/internal/crawl/doc/doc.go index ec2e031ba..4a709f693 100644 --- a/api/internal/crawl/doc/doc.go +++ b/api/internal/crawl/doc/doc.go @@ -2,6 +2,7 @@ package doc import ( "fmt" + "log" "sort" "strings" @@ -83,7 +84,7 @@ func (doc *KustomizationDocument) GetResources() ([]*Document, error) { } next, err := doc.Document.FromRelativePath(r) if err != nil { - fmt.Printf("GetResources error: %v\n", err) + log.Printf("GetResources error: %v\n", err) continue } res = append(res, &next) diff --git a/api/internal/crawl/index/kustomize.go b/api/internal/crawl/index/kustomize.go index 568f7e4ea..e55c5547e 100644 --- a/api/internal/crawl/index/kustomize.go +++ b/api/internal/crawl/index/kustomize.go @@ -253,7 +253,7 @@ func (it *KustomizeIterator) Next() bool { } if it.err == nil { - fmt.Printf("updating scroll: %s\n", *it.scrollImpl.ScrollID) + log.Printf("updating scroll: %s\n", *it.scrollImpl.ScrollID) it.err = it.update(*it.scrollImpl.ScrollID, reader) } @@ -342,7 +342,7 @@ func (ki *KustomizeIndex) Search(query string, if err != nil { return nil, fmt.Errorf("failed to format query %s", query) } - fmt.Printf("formated query: %s\n", data) + log.Printf("formated query: %s\n", data) var kr ElasticKustomizeResult err = ki.index.Search(data, opts.SearchOptions, func(results io.Reader) error {