Skip to content

Commit

Permalink
Fix: fix cli logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Somefive committed Sep 15, 2021
1 parent 8d8447a commit 99996b8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
11 changes: 8 additions & 3 deletions references/a/preimport/preimport.go
Expand Up @@ -28,14 +28,19 @@ var _flagSet *flag.FlagSet

// disable logging during import
func init() {
log.L.Logger.SetLevel(logrus.PanicLevel)
_flagSet = flag.CommandLine
klog.InitFlags(_flagSet)
SuppressLogging()
}

// SuppressLogging disable logging
func SuppressLogging() {
log.L.Logger.SetLevel(logrus.PanicLevel)
_ = _flagSet.Set("v", "-1")
}

// Start recover logging
func Start() {
// ResumeLogging enable logging
func ResumeLogging() {
log.L.Logger.SetLevel(logrus.InfoLevel)
_ = _flagSet.Set("v", "0")
}
5 changes: 5 additions & 0 deletions references/cli/cli.go
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/oam-dev/kubevela/pkg/utils/common"
"github.com/oam-dev/kubevela/pkg/utils/system"
"github.com/oam-dev/kubevela/pkg/utils/util"
"github.com/oam-dev/kubevela/references/a/preimport"
"github.com/oam-dev/kubevela/references/cmd/cli/fake"
"github.com/oam-dev/kubevela/version"
)
Expand Down Expand Up @@ -68,6 +69,10 @@ func NewCommand() *cobra.Command {
os.Exit(1)
}

preimport.SuppressLogging()
_, _ = commandArgs.GetClient()
preimport.ResumeLogging()

cmds.AddCommand(
// Getting Start
NewInitCommand(commandArgs, ioStream),
Expand Down
3 changes: 3 additions & 0 deletions references/cli/cluster.go
Expand Up @@ -38,6 +38,7 @@ import (
"github.com/oam-dev/kubevela/pkg/oam"
"github.com/oam-dev/kubevela/pkg/utils/common"
errors3 "github.com/oam-dev/kubevela/pkg/utils/errors"
"github.com/oam-dev/kubevela/references/a/preimport"
)

const (
Expand Down Expand Up @@ -65,7 +66,9 @@ func ClusterCommandGroup(c common.Args) *cobra.Command {
}
c.Config.Wrap(multicluster.NewSecretModeMultiClusterRoundTripper)
c.Client = nil
preimport.SuppressLogging()
k8sClient, err := c.GetClient()
preimport.ResumeLogging()
if err != nil {
return errors.Wrapf(err, "failed to get k8s client")
}
Expand Down
2 changes: 1 addition & 1 deletion references/cmd/cli/main.go
Expand Up @@ -26,7 +26,7 @@ import (
)

func main() {
preimport.Start()
preimport.ResumeLogging()
rand.Seed(time.Now().UnixNano())

command := cli.NewCommand()
Expand Down

0 comments on commit 99996b8

Please sign in to comment.