Skip to content

Commit

Permalink
ExampleSetLogger: reset state after test
Browse files Browse the repository at this point in the history
When running as a test, the global state must be restored because other tests
also get run.
  • Loading branch information
pohly committed Mar 15, 2022
1 parent 0013f22 commit cd54fdc
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions contextual_test.go
Expand Up @@ -24,6 +24,8 @@ import (
)

func ExampleSetLogger() {
defer klog.ClearLogger()

// Logger is only used as backend, Background() returns klogr.
klog.SetLogger(logr.Discard())
fmt.Printf("logger after SetLogger: %T\n", klog.Background().GetSink())
Expand Down

0 comments on commit cd54fdc

Please sign in to comment.