...
1
16
17 package main
18
19 import (
20 "context"
21 "flag"
22 "fmt"
23 "os"
24 "strings"
25
26 "k8s.io/apimachinery/pkg/util/runtime"
27 "k8s.io/component-base/featuregate"
28 "k8s.io/component-base/logs"
29 logsapi "k8s.io/component-base/logs/api/v1"
30 "k8s.io/component-base/logs/example"
31 "k8s.io/klog/v2"
32
33 _ "k8s.io/component-base/logs/json/register"
34 )
35
36 func main() {
37
38 featureGate := featuregate.NewFeatureGate()
39 runtime.Must(logsapi.AddFeatureGates(featureGate))
40 flag.Var(featureGate, "feature-gate",
41 "A set of key=value pairs that describe feature gates for alpha/experimental features. "+
42 "Options are:\n"+strings.Join(featureGate.KnownFeatures(), "\n"))
43 c := logsapi.NewLoggingConfiguration()
44 logsapi.AddGoFlags(c, flag.CommandLine)
45
46
47
48
49 flag.Parse()
50 logs.InitLogs()
51 if err := logsapi.ValidateAndApply(c, featureGate); err != nil {
52 fmt.Fprintf(os.Stderr, "%v\n", err)
53 os.Exit(1)
54 }
55 args := flag.CommandLine.Args()
56 if len(args) > 0 {
57 fmt.Fprintf(os.Stderr, "Unexpected additional command line arguments:\n %s\n", strings.Join(args, "\n "))
58 os.Exit(1)
59 }
60
61
62 logger := klog.LoggerWithValues(klog.LoggerWithName(klog.Background(), "example"), "foo", "bar")
63 ctx := klog.NewContext(context.Background(), logger)
64
65
66 example.Run(ctx)
67 }
68
View as plain text