2022-01-14 18:49:22 +00:00
|
|
|
// Copyright 2020-2022 the Pinniped contributors. All Rights Reserved.
|
2020-11-10 13:48:42 +00:00
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
package plog
|
|
|
|
|
2020-11-10 16:23:42 +00:00
|
|
|
import (
|
2021-02-05 01:02:38 +00:00
|
|
|
"fmt"
|
2020-11-10 16:23:42 +00:00
|
|
|
|
2021-01-26 22:34:27 +00:00
|
|
|
"k8s.io/klog/v2"
|
2020-11-10 16:23:42 +00:00
|
|
|
)
|
|
|
|
|
2021-02-05 01:02:38 +00:00
|
|
|
// 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())
|
|
|
|
}
|
|
|
|
|
2021-10-20 11:59:24 +00:00
|
|
|
func klogLevelForPlogLevel(plogLevel LogLevel) klog.Level {
|
2021-01-26 22:34:27 +00:00
|
|
|
switch plogLevel {
|
|
|
|
case LevelWarning:
|
2021-10-20 11:59:24 +00:00
|
|
|
return klogLevelWarning // unset means minimal logs (Error and Warning)
|
2021-01-26 22:34:27 +00:00
|
|
|
case LevelInfo:
|
2021-10-20 11:59:24 +00:00
|
|
|
return klogLevelInfo
|
2021-01-26 22:34:27 +00:00
|
|
|
case LevelDebug:
|
2021-10-20 11:59:24 +00:00
|
|
|
return klogLevelDebug
|
2021-01-26 22:34:27 +00:00
|
|
|
case LevelTrace:
|
2021-10-20 11:59:24 +00:00
|
|
|
return klogLevelTrace
|
2021-01-26 22:34:27 +00:00
|
|
|
case LevelAll:
|
2021-10-20 11:59:24 +00:00
|
|
|
return klogLevelAll + 100 // make all really mean all
|
2021-01-26 22:34:27 +00:00
|
|
|
default:
|
2021-10-20 11:59:24 +00:00
|
|
|
return -1
|
2021-01-26 22:34:27 +00:00
|
|
|
}
|
|
|
|
}
|