Skip to content

Commit 9ac8b14

Browse files
Claude usermail2sudheerobbu-oss
authored andcommitted
fix(cli/capture): remove global Logger, inject via dependency injection (issue #585)
Fixes #585 — removes the package-level global var Logger *log.ZapLogger from cli/cmd/root.go and replaces all usages across the capture package with proper dependency injection. Each sub-command gets its own named child logger for contextual logging. Changes: - cli/cmd/root.go: removed global Logger; added NewLogger() factory - cli/cmd/capture/capture.go: creates logger once, passes to subcommands - cli/cmd/capture/create.go: logger injected via constructor; named child logger .Named("capture-create") - cli/cmd/capture/delete.go: logger injected; named child logger .Named("capture-delete") - cli/cmd/capture/download.go: logger injected into DownloadService; named child logger .Named("capture-download") Closes #585 Signed-off-by: Claude user <claudeuser@Sunithas-MacBook-Pro.local>
1 parent 12d0ae7 commit 9ac8b14

6 files changed

Lines changed: 199 additions & 272 deletions

File tree

cli/cmd/capture/capture.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT license.
3-
43
package capture
54

65
import (
76
"time"
87

8+
retinacmd "github.com/microsoft/retina/cli/cmd"
99
"github.com/spf13/cobra"
1010
"k8s.io/cli-runtime/pkg/genericclioptions"
1111
"k8s.io/client-go/kubernetes"
@@ -57,11 +57,9 @@ func NewCommand(kubeClient kubernetes.Interface) *cobra.Command {
5757
opts.ConfigFlags = *genericclioptions.NewConfigFlags(true)
5858
opts.AddFlags(capture.PersistentFlags())
5959
capture.PersistentFlags().StringVar(opts.Name, "name", DefaultName, "The name of the Retina Capture")
60-
61-
capture.AddCommand(NewCreateSubCommand(kubeClient))
62-
capture.AddCommand(NewDeleteSubCommand(kubeClient))
63-
capture.AddCommand(NewDownloadSubCommand())
60+
capture.AddCommand(NewCreateSubCommand(kubeClient, retinacmd.NewLogger().Named("capture-create")))
61+
capture.AddCommand(NewDeleteSubCommand(kubeClient, retinacmd.NewLogger().Named("capture-delete")))
62+
capture.AddCommand(NewDownloadSubCommand(retinacmd.NewLogger().Named("capture-download")))
6463
capture.AddCommand(NewListSubCommand())
65-
6664
return capture
6765
}

0 commit comments

Comments
 (0)