From 034dde5e99084272196d08959d9f88b61a98133d Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Thu, 12 Dec 2024 19:42:10 +0000 Subject: [PATCH 1/2] warnings to slog Signed-off-by: Austin Abro --- src/pkg/packager/create.go | 3 --- src/pkg/packager/deploy.go | 6 ------ src/pkg/packager/interactive.go | 4 +++- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/src/pkg/packager/create.go b/src/pkg/packager/create.go index fcc04478e7..13209658c3 100755 --- a/src/pkg/packager/create.go +++ b/src/pkg/packager/create.go @@ -56,9 +56,6 @@ func (p *Packager) Create(ctx context.Context) error { } // Store on packager config p.cfg.Pkg = pkg - for _, warning := range warnings { - l.Warn(warning) - } l.Info("package loaded", "kind", pkg.Kind, "name", pkg.Metadata.Name, diff --git a/src/pkg/packager/deploy.go b/src/pkg/packager/deploy.go index c2f7f0b58b..0c532c5130 100644 --- a/src/pkg/packager/deploy.go +++ b/src/pkg/packager/deploy.go @@ -94,18 +94,12 @@ func (p *Packager) Deploy(ctx context.Context) error { return err } warnings = append(warnings, validateWarnings...) - for _, warning := range validateWarnings { - l.Warn(warning) - } sbomViewFiles, sbomWarnings, err := p.layout.SBOMs.StageSBOMViewFiles() if err != nil { return err } warnings = append(warnings, sbomWarnings...) - for _, warning := range sbomWarnings { - l.Warn(warning) - } // Confirm the overall package deployment if !p.confirmAction(ctx, config.ZarfDeployStage, warnings, sbomViewFiles) { diff --git a/src/pkg/packager/interactive.go b/src/pkg/packager/interactive.go index 7b862ce6f2..a8261e7510 100644 --- a/src/pkg/packager/interactive.go +++ b/src/pkg/packager/interactive.go @@ -23,6 +23,7 @@ import ( func (p *Packager) confirmAction(ctx context.Context, stage string, warnings []string, sbomViewFiles []string) bool { pterm.Println() message.HeaderInfof("📦 PACKAGE DEFINITION") + l := logger.From(ctx) err := utils.ColorPrintYAML(p.cfg.Pkg, p.getPackageYAMLHints(stage), true) if err != nil { message.WarnErr(err, "unable to print yaml") @@ -52,7 +53,7 @@ func (p *Packager) confirmAction(ctx context.Context, stage string, warnings []s message.Note(msg) pterm.Println(viewNow) pterm.Println(viewLater) - logger.From(ctx).Info("this package has SBOMs available for review in a temporary directory", "directory", filepath.Join(cwd, layout.SBOMDir)) + l.Info("this package has SBOMs available for review in a temporary directory", "directory", filepath.Join(cwd, layout.SBOMDir)) } else { message.Warn("This package does NOT contain an SBOM. If you require an SBOM, please contact the creator of this package to request a version that includes an SBOM.") } @@ -64,6 +65,7 @@ func (p *Packager) confirmAction(ctx context.Context, stage string, warnings []s message.Title("Package Warnings", "the following warnings were flagged while reading the package") for _, warning := range warnings { message.Warn(warning) + l.Warn(warning) } } From f4e4eea818af380418c06b67b51842c920f42cc9 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Thu, 12 Dec 2024 19:42:31 +0000 Subject: [PATCH 2/2] slog destination Signed-off-by: Austin Abro --- src/pkg/logger/logger.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pkg/logger/logger.go b/src/pkg/logger/logger.go index a125888313..40ec1ae513 100644 --- a/src/pkg/logger/logger.go +++ b/src/pkg/logger/logger.go @@ -188,7 +188,7 @@ func New(cfg Config) (*slog.Logger, error) { }) case FormatDev: opts.AddSource = true - handler = devslog.NewHandler(DestinationDefault, &devslog.Options{ + handler = devslog.NewHandler(cfg.Destination, &devslog.Options{ HandlerOptions: &opts, NewLineAfterLog: true, NoColor: !bool(cfg.Color),