Skip to content

Commit

Permalink
Add debug log flag
Browse files Browse the repository at this point in the history
  • Loading branch information
alenkacz committed Dec 30, 2020
1 parent 17a6947 commit 3caa9a2
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions pkg/cmd/verify/deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,23 @@ package verify
import (
"context"
"fmt"
"os"
"time"

"github.com/alenkacz/cert-manager-verifier/pkg/verify"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/kubernetes"
"os"
"github.com/sirupsen/logrus"
"time"
)

const defaultTimeout = 2 * time.Minute

type Options struct {
ConfigFlags *genericclioptions.ConfigFlags
Streams *genericclioptions.IOStreams
DebugLogs bool
}

func NewOptions() *Options {
Expand Down Expand Up @@ -46,6 +48,8 @@ func NewCmd() *cobra.Command {
},
}

rootCmd.Flags().BoolVar(&options.DebugLogs, "debug", false, "If true, will print out debug logs (default false)")

options.ConfigFlags.AddFlags(rootCmd.Flags())
rootCmd.SetOut(options.Streams.Out)
rootCmd.SilenceUsage = true
Expand All @@ -59,6 +63,9 @@ func NewCmd() *cobra.Command {
func (o *Options) Execute() error {
logrus.SetOutput(o.Streams.Out)
logrus.SetFormatter(SimpleFormatter{})
if o.DebugLogs {
logrus.SetLevel(logrus.DebugLevel)
}

ctx, cancel := context.WithTimeout(context.Background(), defaultTimeout)
defer cancel()
Expand Down Expand Up @@ -127,8 +134,8 @@ func formatDeploymentResult(result []verify.DeploymentResult) string {
return formattedResult
}

type SimpleFormatter struct {}
type SimpleFormatter struct{}

func (SimpleFormatter) Format(entry *logrus.Entry) ([]byte, error) {
return []byte(entry.Message), nil
}
}

0 comments on commit 3caa9a2

Please sign in to comment.