internal/plog: add KObj() and KRef()

Signed-off-by: Andrew Keesler <akeesler@vmware.com>
This commit is contained in:
Andrew Keesler 2021-02-04 20:02:38 -05:00
parent 44b7679e9f
commit ae6503e972
No known key found for this signature in database
GPG Key ID: 27CE0444346F9413
1 changed files with 12 additions and 0 deletions

View File

@ -4,6 +4,7 @@
package plog package plog
import ( import (
"fmt"
"sync" "sync"
"github.com/spf13/pflag" "github.com/spf13/pflag"
@ -32,6 +33,17 @@ func RemoveKlogGlobalFlags() {
} }
} }
// KRef is (mostly) copied from klog - it is a standard way to represent a a metav1.Object in logs
// when you only have access to the namespace and name of the object.
func KRef(namespace, name string) string {
return fmt.Sprintf("%s/%s", namespace, name)
}
// KObj is (mostly) copied from klog - it is a standard way to represent a metav1.Object in logs.
func KObj(obj klog.KMetadata) string {
return fmt.Sprintf("%s/%s", obj.GetNamespace(), obj.GetName())
}
func klogLevelForPlogLevel(plogLevel LogLevel) (klogLevel klog.Level) { func klogLevelForPlogLevel(plogLevel LogLevel) (klogLevel klog.Level) {
switch plogLevel { switch plogLevel {
case LevelWarning: case LevelWarning: