Fix: fix cli logging (#2298)

This commit is contained in:
Somefive
2021-09-15 13:18:50 +08:00
committed by GitHub
parent 9a766467a3
commit 291f9d139e
4 changed files with 17 additions and 4 deletions
+8 -3
View File
@@ -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
View File
@@ -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"
)
@@ -68,6 +69,10 @@ func NewCommand() *cobra.Command {
os.Exit(1)
}
preimport.SuppressLogging()
_, _ = commandArgs.GetClient()
preimport.ResumeLogging()
cmds.AddCommand(
// Getting Start
NewInitCommand(commandArgs, ioStream),
+3
View File
@@ -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 (
@@ -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")
}
+1 -1
View File
@@ -26,7 +26,7 @@ import (
)
func main() {
preimport.Start()
preimport.ResumeLogging()
rand.Seed(time.Now().UnixNano())
command := cli.NewCommand()