From 68db728b269e79d4ded2a4b75e6c01bcd753d348 Mon Sep 17 00:00:00 2001 From: Eric Hotinger Date: Mon, 6 Aug 2018 11:01:10 -0700 Subject: [PATCH] Use log instead of fmt in several places (#191) * Use log instead of fmt in several places, add a few new log lines for timing --- baseimages/scanner/cmd/scan.go | 2 +- builder/builder.go | 2 ++ builder/push.go | 1 + builder/setup_linux.go | 2 +- cmd/build.go | 3 ++- cmd/exec.go | 3 ++- templating/engine.go | 3 ++- 7 files changed, 11 insertions(+), 5 deletions(-) diff --git a/baseimages/scanner/cmd/scan.go b/baseimages/scanner/cmd/scan.go index e3904abb..4f0634a9 100644 --- a/baseimages/scanner/cmd/scan.go +++ b/baseimages/scanner/cmd/scan.go @@ -6,9 +6,9 @@ package cmd import ( "context" "encoding/json" + "fmt" "os" - "fmt" "io" "time" diff --git a/builder/builder.go b/builder/builder.go index c4a3a713..e009701e 100644 --- a/builder/builder.go +++ b/builder/builder.go @@ -40,9 +40,11 @@ func NewBuilder(tm *taskmanager.TaskManager, debug bool, workspaceDir string) *B // RunAllBuildSteps executes a pipeline. func (b *Builder) RunAllBuildSteps(ctx context.Context, pipeline *graph.Pipeline) error { if !b.taskManager.DryRun { + log.Printf("Setting up Docker configuration...") if err := b.setupConfig(ctx); err != nil { return err } + log.Printf("Successfully set up Docker configuration") if pipeline.UsingRegistryCreds() { log.Printf("Logging in to registry: %s\n", pipeline.RegistryName) if err := b.dockerLoginWithRetries(ctx, pipeline.RegistryName, pipeline.RegistryUsername, pipeline.RegistryPassword, 0); err != nil { diff --git a/builder/push.go b/builder/push.go index f42e0835..db564df0 100644 --- a/builder/push.go +++ b/builder/push.go @@ -47,6 +47,7 @@ func (b *Builder) pushWithRetries(ctx context.Context, images []string) error { time.Sleep(500 * time.Millisecond) retry++ } else { + log.Printf("Successfully pushed image: %s\n", img) break } } diff --git a/builder/setup_linux.go b/builder/setup_linux.go index 49ec4d8f..dafbd3d6 100644 --- a/builder/setup_linux.go +++ b/builder/setup_linux.go @@ -37,7 +37,7 @@ func (b *Builder) setupConfig(ctx context.Context) error { var buf bytes.Buffer if err := b.taskManager.Run(ctx, args, nil, &buf, &buf, ""); err != nil { - return errors.Wrap(err, fmt.Sprintf("failed to setup config: %s", buf.String())) + return errors.Wrap(err, fmt.Sprintf("failed to setup config, msg: %s", buf.String())) } return nil diff --git a/cmd/build.go b/cmd/build.go index 60dded3e..6a807efa 100644 --- a/cmd/build.go +++ b/cmd/build.go @@ -8,6 +8,7 @@ import ( "errors" "fmt" "io" + "log" "strings" "time" @@ -167,7 +168,7 @@ func (b *buildCmd) run(cmd *cobra.Command, args []string) error { homeVolName = b.homeVol } - fmt.Printf("Using %s as the home volume\n", homeVolName) + log.Printf("Using %s as the home volume\n", homeVolName) builder := builder.NewBuilder(taskManager, debug, homeVolName) defer builder.CleanAllBuildSteps(context.Background(), pipeline) return builder.RunAllBuildSteps(ctx, pipeline) diff --git a/cmd/exec.go b/cmd/exec.go index 1ab24821..285ef5d3 100644 --- a/cmd/exec.go +++ b/cmd/exec.go @@ -7,6 +7,7 @@ import ( "context" "fmt" "io" + "log" "time" "github.com/Azure/acr-builder/builder" @@ -104,7 +105,7 @@ func (e *execCmd) run(cmd *cobra.Command, args []string) error { homeVolName = e.homeVol } - fmt.Printf("Using %s as the home volume\n", homeVolName) + log.Printf("Using %s as the home volume\n", homeVolName) builder := builder.NewBuilder(taskManager, debug, homeVolName) defer builder.CleanAllBuildSteps(context.Background(), pipeline) return builder.RunAllBuildSteps(ctx, pipeline) diff --git a/templating/engine.go b/templating/engine.go index a094756f..39cb805b 100644 --- a/templating/engine.go +++ b/templating/engine.go @@ -7,6 +7,7 @@ import ( "bytes" "errors" "fmt" + "log" "sort" "strings" "text/template" @@ -57,7 +58,7 @@ func (e *Engine) render(templates map[string]renderableTemplate) (rendered map[s // If a template panics, recover the engine. defer func() { if r := recover(); r != nil { - fmt.Printf("Template rendering recovered. Value: %v\n", r) + log.Printf("Template rendering recovered. Value: %v\n", r) } }()