From 16bf8c4008da9cd41972a4845897ebfbbead5d4c Mon Sep 17 00:00:00 2001 From: Wojciech Tyczynski Date: Wed, 13 Jul 2016 13:16:25 +0200 Subject: [PATCH] Unify logging in generators and avoid annoying logs. --- cmd/libs/go2idl/client-gen/main.go | 5 ++--- cmd/libs/go2idl/generator/execute.go | 9 +++++---- .../go2idl/import-boss/generators/import_restrict.go | 10 ++++++---- cmd/libs/go2idl/parser/parse.go | 8 ++++---- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/cmd/libs/go2idl/client-gen/main.go b/cmd/libs/go2idl/client-gen/main.go index 6be11f68ed7..f33123ab6f4 100644 --- a/cmd/libs/go2idl/client-gen/main.go +++ b/cmd/libs/go2idl/client-gen/main.go @@ -20,14 +20,13 @@ package main import ( "fmt" "path/filepath" + "strings" "k8s.io/kubernetes/cmd/libs/go2idl/args" clientgenargs "k8s.io/kubernetes/cmd/libs/go2idl/client-gen/args" "k8s.io/kubernetes/cmd/libs/go2idl/client-gen/generators" "k8s.io/kubernetes/pkg/api/unversioned" - "strings" - "github.com/golang/glog" flag "github.com/spf13/pflag" ) @@ -182,7 +181,7 @@ func main() { IncludedTypesOverrides: includedTypesOverrides, } - fmt.Printf("==arguments: %v\n", arguments) + glog.Infof("==arguments: %v\n", arguments) } if err := arguments.Execute( diff --git a/cmd/libs/go2idl/generator/execute.go b/cmd/libs/go2idl/generator/execute.go index 5dc4908f8ae..5f822a6c8f9 100644 --- a/cmd/libs/go2idl/generator/execute.go +++ b/cmd/libs/go2idl/generator/execute.go @@ -22,13 +22,14 @@ import ( "go/format" "io" "io/ioutil" - "log" "os" "path/filepath" "strings" "k8s.io/kubernetes/cmd/libs/go2idl/namer" "k8s.io/kubernetes/cmd/libs/go2idl/types" + + "github.com/golang/glog" ) func errs2strings(errors []error) []string { @@ -63,7 +64,7 @@ type DefaultFileType struct { } func (ft DefaultFileType) AssembleFile(f *File, pathname string) error { - log.Printf("Assembling file %q", pathname) + glog.V(0).Infof("Assembling file %q", pathname) destFile, err := os.Create(pathname) if err != nil { return err @@ -90,7 +91,7 @@ func (ft DefaultFileType) AssembleFile(f *File, pathname string) error { } func (ft DefaultFileType) VerifyFile(f *File, pathname string) error { - log.Printf("Verifying file %q", pathname) + glog.V(0).Infof("Verifying file %q", pathname) friendlyName := filepath.Join(f.PackageName, f.Name) b := &bytes.Buffer{} et := NewErrorTracker(b) @@ -210,7 +211,7 @@ func (c *Context) addNameSystems(namers namer.NameSystems) *Context { // import path already, this will be appended to 'outDir'. func (c *Context) ExecutePackage(outDir string, p Package) error { path := filepath.Join(outDir, p.Path()) - log.Printf("Processing package %q, disk location %q", p.Name(), path) + glog.V(0).Infof("Processing package %q, disk location %q", p.Name(), path) // Filter out any types the *package* doesn't care about. packageContext := c.filteredBy(p.Filter) os.MkdirAll(path, 0755) diff --git a/cmd/libs/go2idl/import-boss/generators/import_restrict.go b/cmd/libs/go2idl/import-boss/generators/import_restrict.go index c76538fdf51..81818057b93 100644 --- a/cmd/libs/go2idl/import-boss/generators/import_restrict.go +++ b/cmd/libs/go2idl/import-boss/generators/import_restrict.go @@ -32,6 +32,8 @@ import ( "k8s.io/kubernetes/cmd/libs/go2idl/generator" "k8s.io/kubernetes/cmd/libs/go2idl/namer" "k8s.io/kubernetes/cmd/libs/go2idl/types" + + "github.com/golang/glog" ) const ( @@ -200,19 +202,19 @@ func (importRuleFile) VerifyFile(f *generator.File, path string) error { return fmt.Errorf("regexp `%s` in file %q doesn't compile: %v", r.SelectorRegexp, actualPath, err) } for v := range f.Imports { - // fmt.Printf("Checking %v matches %v: %v\n", r.SelectorRegexp, v, re.MatchString(v)) + glog.V(4).Infof("Checking %v matches %v: %v\n", r.SelectorRegexp, v, re.MatchString(v)) if !re.MatchString(v) { continue } for _, forbidden := range r.ForbiddenPrefixes { - // fmt.Printf("Checking %v against %v\n", v, forbidden) + glog.V(4).Infof("Checking %v against %v\n", v, forbidden) if strings.HasPrefix(v, forbidden) { return fmt.Errorf("import %v has forbidden prefix %v", v, forbidden) } } found := false for _, allowed := range r.AllowedPrefixes { - fmt.Printf("Checking %v against %v\n", v, allowed) + glog.V(0).Infof("Checking %v against %v\n", v, allowed) if strings.HasPrefix(v, allowed) { found = true break @@ -224,7 +226,7 @@ func (importRuleFile) VerifyFile(f *generator.File, path string) error { } } if len(rules.Rules) > 0 { - fmt.Printf("%v passes rules found in %v\n", path, actualPath) + glog.V(0).Infof("%v passes rules found in %v\n", path, actualPath) } return nil diff --git a/cmd/libs/go2idl/parser/parse.go b/cmd/libs/go2idl/parser/parse.go index 2482d995808..4ed9acc8d29 100644 --- a/cmd/libs/go2idl/parser/parse.go +++ b/cmd/libs/go2idl/parser/parse.go @@ -79,7 +79,7 @@ func New() *Builder { // The returned string will have some/path/bin/go, so remove the last two elements. c.GOROOT = filepath.Dir(filepath.Dir(strings.Trim(string(p), "\n"))) } else { - fmt.Printf("Warning: $GOROOT not set, and unable to run `which go` to find it: %v\n", err) + glog.Warningf("Warning: $GOROOT not set, and unable to run `which go` to find it: %v\n", err) } } // Force this to off, since we don't properly parse CGo. All symbols must @@ -304,7 +304,7 @@ func (b *Builder) importer(imports map[string]*tc.Package, path string) (*tc.Pac pkg, err := b.typeCheckPackage(path) if err != nil { if ignoreError && pkg != nil { - fmt.Printf("type checking encountered some errors in %q, but ignoring.\n", path) + glog.V(2).Infof("type checking encountered some errors in %q, but ignoring.\n", path) } else { return nil, err } @@ -350,7 +350,7 @@ func (b *Builder) typeCheckPackage(id string) (*tc.Package, error) { // method. So there can't be cycles in the import graph. Importer: importAdapter{b}, Error: func(err error) { - fmt.Printf("type checker error: %v\n", err) + glog.V(2).Infof("type checker error: %v\n", err) }, } pkg, err := c.Check(id, b.fset, files, nil) @@ -685,7 +685,7 @@ func (b *Builder) walkType(u types.Universe, useName *types.Name, in tc.Type) *t return out } out.Kind = types.Unsupported - fmt.Printf("Making unsupported type entry %q for: %#v\n", out, t) + glog.Warningf("Making unsupported type entry %q for: %#v\n", out, t) return out } }