...

Source file src/k8s.io/klog/v2/integration_tests/internal/main.go

Documentation: k8s.io/klog/v2/integration_tests/internal

     1  /*
     2  
     3  This file is intended to be used as a standin for a klog'ed executable.
     4  
     5  It is called by the integration test via `go run` and with different klog
     6  flags to assert on klog behaviour, especially where klog logs its output
     7  when different combinations of the klog flags are at play.
     8  
     9  This file is not intended to be used outside of the integration tests and
    10  is not supposed to be a (good) example on how to use klog.
    11  
    12  */
    13  
    14  package main
    15  
    16  import (
    17  	"flag"
    18  	"fmt"
    19  	"os"
    20  
    21  	"k8s.io/klog/v2"
    22  )
    23  
    24  func main() {
    25  	infoLogLine := getEnvOrDie("KLOG_INFO_LOG")
    26  	warningLogLine := getEnvOrDie("KLOG_WARNING_LOG")
    27  	errorLogLine := getEnvOrDie("KLOG_ERROR_LOG")
    28  	fatalLogLine := getEnvOrDie("KLOG_FATAL_LOG")
    29  
    30  	klog.InitFlags(nil)
    31  	flag.Parse()
    32  	klog.Info(infoLogLine)
    33  	klog.Warning(warningLogLine)
    34  	klog.Error(errorLogLine)
    35  	klog.Flush()
    36  	klog.Fatal(fatalLogLine)
    37  }
    38  
    39  func getEnvOrDie(name string) string {
    40  	val, ok := os.LookupEnv(name)
    41  	if !ok {
    42  		fmt.Fprintf(os.Stderr, name+" could not be found in environment")
    43  		os.Exit(1)
    44  	}
    45  	return val
    46  }
    47  

View as plain text