From 1d75db11720bb542847a7f42d99a5bd7f68bc029 Mon Sep 17 00:00:00 2001 From: Timofey Kirillov Date: Fri, 27 Jan 2023 19:24:13 +0300 Subject: [PATCH] fix(logging): simplify logs, remove excess messages - hide push image layer messages when using Buildah mode (show in verbose); - hide synchronization messages (show in verbose); Signed-off-by: Timofey Kirillov --- cmd/werf/common/synchronization.go | 4 ++-- pkg/container_backend/buildah_backend.go | 28 ++++++++++++++++++++---- pkg/deploy/bundles/publish.go | 2 +- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/cmd/werf/common/synchronization.go b/cmd/werf/common/synchronization.go index 5903ece0a6..65988565f1 100644 --- a/cmd/werf/common/synchronization.go +++ b/cmd/werf/common/synchronization.go @@ -132,13 +132,13 @@ func GetSynchronization(ctx context.Context, cmdData *CmdData, projectName strin getHttpParamsFunc := func(synchronization string, stagesStorage storage.StagesStorage) (*SynchronizationParams, error) { var address string - if err := logboek.Default().LogProcess(fmt.Sprintf("Getting client id for the http synchronization server")). + if err := logboek.Info().LogProcess(fmt.Sprintf("Getting client id for the http synchronization server")). DoError(func() error { if clientID, err := synchronization_server.GetOrCreateClientID(ctx, projectName, synchronization_server.NewSynchronizationClient(synchronization), stagesStorage); err != nil { return fmt.Errorf("unable to get synchronization client id: %w", err) } else { address = fmt.Sprintf("%s/%s", synchronization, clientID) - logboek.Default().LogF("Using clientID %q for http synchronization server at address %s\n", clientID, address) + logboek.Info().LogF("Using clientID %q for http synchronization server at address %s\n", clientID, address) return nil } }); err != nil { diff --git a/pkg/container_backend/buildah_backend.go b/pkg/container_backend/buildah_backend.go index befa5899a2..0efde4ffb0 100644 --- a/pkg/container_backend/buildah_backend.go +++ b/pkg/container_backend/buildah_backend.go @@ -586,29 +586,49 @@ func (runtime *BuildahBackend) GetImageInfo(ctx context.Context, ref string, opt } func (runtime *BuildahBackend) Rmi(ctx context.Context, ref string, opts RmiOpts) error { + var logWriter io.Writer + if logboek.Context(ctx).Info().IsAccepted() { + logWriter = logboek.Context(ctx).OutStream() + } + return runtime.buildah.Rmi(ctx, ref, buildah.RmiOpts{ Force: true, CommonOpts: buildah.CommonOpts{ - LogWriter: logboek.Context(ctx).OutStream(), + LogWriter: logWriter, }, }) } func (runtime *BuildahBackend) Pull(ctx context.Context, ref string, opts PullOpts) error { + var logWriter io.Writer + if logboek.Context(ctx).Info().IsAccepted() { + logWriter = logboek.Context(ctx).OutStream() + } + return runtime.buildah.Pull(ctx, ref, buildah.PullOpts{ - LogWriter: logboek.Context(ctx).OutStream(), + LogWriter: logWriter, }) } func (runtime *BuildahBackend) Tag(ctx context.Context, ref, newRef string, opts TagOpts) error { + var logWriter io.Writer + if logboek.Context(ctx).Info().IsAccepted() { + logWriter = logboek.Context(ctx).OutStream() + } + return runtime.buildah.Tag(ctx, ref, newRef, buildah.TagOpts{ - LogWriter: logboek.Context(ctx).OutStream(), + LogWriter: logWriter, }) } func (runtime *BuildahBackend) Push(ctx context.Context, ref string, opts PushOpts) error { + var logWriter io.Writer + if logboek.Context(ctx).Info().IsAccepted() { + logWriter = logboek.Context(ctx).OutStream() + } + return runtime.buildah.Push(ctx, ref, buildah.PushOpts{ - LogWriter: logboek.Context(ctx).OutStream(), + LogWriter: logWriter, }) } diff --git a/pkg/deploy/bundles/publish.go b/pkg/deploy/bundles/publish.go index 526051bd54..c76d50ca93 100644 --- a/pkg/deploy/bundles/publish.go +++ b/pkg/deploy/bundles/publish.go @@ -20,7 +20,7 @@ func Publish(ctx context.Context, bundle *chart_extender.Bundle, bundleRef strin loader.GlobalLoadOptions = &loader.LoadOptions{} - if err := logboek.Context(ctx).LogProcess("Saving bundle to the local chart helm cache").DoError(func() error { + if err := logboek.Context(ctx).Default().LogProcess("Saving bundle to the local chart helm cache").DoError(func() error { path, err := filepath.Abs(bundle.Dir) if err != nil { return err