Init useful flags for klog/v2

This commit is contained in:
Ciprian Hacman
2023-09-17 11:00:42 +03:00
parent e43459d86d
commit 5210373640
20 changed files with 69 additions and 1869 deletions
+11 -11
View File
@@ -19,7 +19,6 @@ package main
import (
"flag"
"fmt"
"os"
"strings"
"time"
@@ -29,10 +28,6 @@ import (
"k8s.io/node-problem-detector/test/e2e/problemmaker/makers"
)
func init() {
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
}
type options struct {
// Command line options. See flag descriptions for the description
Rate float32
@@ -54,12 +49,17 @@ func (o *options) AddFlags(fs *pflag.FlagSet) {
}
func main() {
// Set klog flag so that it does not log to files.
klog.InitFlags(nil)
if err := flag.Set("logtostderr", "true"); err != nil {
fmt.Printf("Failed to set logtostderr=true: %v\n", err)
os.Exit(1)
}
klogFlags := flag.NewFlagSet("klog", flag.ExitOnError)
klog.InitFlags(klogFlags)
klogFlags.VisitAll(func(f *flag.Flag) {
switch f.Name {
case "v", "vmodule", "logtostderr":
flag.CommandLine.Var(f.Value, f.Name, f.Usage)
}
})
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
pflag.CommandLine.MarkHidden("vmodule")
pflag.CommandLine.MarkHidden("logtostderr")
o := options{}
o.AddFlags(pflag.CommandLine)