File tree Expand file tree Collapse file tree 1 file changed +25
-3
lines changed
staging/src/k8s.io/component-base/logs Expand file tree Collapse file tree 1 file changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -50,12 +50,34 @@ func NewOptions() *Options {
50
50
}
51
51
}
52
52
53
- // Validate check LogFormat in registry or not
53
+ // Validate verifies if any unsupported flag is set
54
+ // for non-default logging format
54
55
func (o * Options ) Validate () []error {
56
+ errs := []error {}
57
+ if o .LogFormat != defaultLogFormat {
58
+ allFlags := unsupportedLoggingFlags ()
59
+ for _ , fname := range allFlags {
60
+ if flagIsSet (fname ) {
61
+ errs = append (errs , fmt .Errorf ("non-default logging format doesn't honor flag: %s" , fname ))
62
+ }
63
+ }
64
+ }
55
65
if _ , err := o .Get (); err != nil {
56
- return []error {fmt .Errorf ("unsupported log format: %s" , o .LogFormat )}
66
+ errs = append (errs , fmt .Errorf ("unsupported log format: %s" , o .LogFormat ))
67
+ }
68
+ return errs
69
+ }
70
+
71
+ func flagIsSet (name string ) bool {
72
+ f := flag .Lookup (name )
73
+ if f != nil {
74
+ return f .DefValue != f .Value .String ()
75
+ }
76
+ pf := pflag .Lookup (name )
77
+ if pf != nil {
78
+ return pf .DefValue != pf .Value .String ()
57
79
}
58
- return nil
80
+ panic ( "failed to lookup unsupported log flag" )
59
81
}
60
82
61
83
// AddFlags add logging-format flag
You can’t perform that action at this time.
0 commit comments