Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions cli/internal/cmd/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,6 @@ func (f *applyFlags) parse(flags *pflag.FlagSet) error {

// runApply sets up the apply command and runs it.
func runApply(cmd *cobra.Command, _ []string) error {
log, err := newCLILogger(cmd)
if err != nil {
return fmt.Errorf("creating logger: %w", err)
}
spinner, err := newSpinnerOrStderr(cmd)
if err != nil {
return err
Expand All @@ -227,7 +223,7 @@ func runApply(cmd *cobra.Command, _ []string) error {
}

fileHandler := file.NewHandler(afero.NewOsFs())
logger, err := newDebugFileLogger(cmd, fileHandler)
debugLogger, err := newDebugFileLogger(cmd, fileHandler)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why we have two loggers in this func. Should we just log everything with this logger?

Copy link
Contributor Author

@3u13r 3u13r Oct 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other logger log is now only used in the warnLogger, which in turn is only used https://github.com/edgelesssys/constellation/blob/euler/cli/extend-file-debug-log/cli/internal/cmd/applyinit.go#L33. I think in general terms, we want to print warning non-structured, so not with slog.

The simplest solution would be to use the debugLogger instead of log when creating the warnLogger and in the warnLogger's implementation we debug log additionally when calling Warn.
EDIT: this would print the warning twice to the user, once structured and once unstructured when debug is enabled, which is fine in my opinion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current state (last commit) is a proposal for this version.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that printing the warning as structured debug log again is fine.

if err != nil {
return err
}
Expand All @@ -250,15 +246,15 @@ func runApply(cmd *cobra.Command, _ []string) error {
)
}

applier := constellation.NewApplier(log, spinner, constellation.ApplyContextCLI, newDialer)
applier := constellation.NewApplier(debugLogger, spinner, constellation.ApplyContextCLI, newDialer)

apply := &applyCmd{
fileHandler: fileHandler,
flags: flags,
log: logger,
wLog: &warnLogger{cmd: cmd, log: log},
log: debugLogger,
wLog: &warnLogger{cmd: cmd, log: debugLogger},
spinner: spinner,
merger: &kubeconfigMerger{log: log},
merger: &kubeconfigMerger{log: debugLogger},
newInfraApplier: newInfraApplier,
imageFetcher: imagefetcher.New(),
applier: applier,
Expand Down Expand Up @@ -826,6 +822,7 @@ func (wl warnLogger) Info(msg string, args ...any) {
// Warn prints a formatted warning from the validator.
func (wl warnLogger) Warn(msg string, args ...any) {
wl.cmd.PrintErrf("Warning: %s %s\n", msg, fmt.Sprint(args...))
wl.log.Debug(msg, args...)
}

type warnLog interface {
Expand Down