3
klog.V(1).Info("succesfully created deployment clientset in detailed")

is not priniting anything in command line though i imported

"github.com/kubernetes/klog"

.how to use debug level klogs using verbosity levels

2
  • Please show all relevant code. Commented Feb 13, 2020 at 9:43
  • 1
    I have the same issue. I grabbed code that uses klog from here github.com/kubernetes/kubernetes/tree/release-1.16/test/images/…. I tied also to add klog.SetOutput(os.Stdout) within the init method but I do not see any expted log entries in the stdout. I assume the klog.V(N)... match the -v N flag whe you use kubectll logs. Using "go.uber.org/zap" I see logs in stdout as expected Commented Feb 15, 2020 at 16:24

2 Answers 2

4

You need to pass "-v=1" to print it.

"-v=n" will print log entries with verbosity <= n.

Besides, if you write the program, you should also parse klog args before they take effect, put the code below in the begining of your main function:

klog.InitFlags(nil) // initializing the flags
defer klog.Flush()  // flushes all pending log I/O

flag.Parse() // parses the command-line flags

klog.Info("now you can see me")
Sign up to request clarification or add additional context in comments.

Comments

-3

It will show output only if verbosity is enabled

3 Comments

Could you please show me how and where enable it? Thanks
enabling in the sense, if you are debugging ur code it will be enabled automatically .if u are running normally without debug it will be off
That's what I did it to enable the desired verbosity via flag (): func main() { loggingFlags := flag.NewFlagSet("webhook", flag.ExitOnError) loggingFlags.StringVar(....). klog.InitFlags(loggingFlags) loggingFlags.Parse(os.Args[1:]) ....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.