cleanup: Avoid usage of numbers

Add seperate functions to handle all
levels and types of logging.

Signed-off-by: Yug <yuggupta27@gmail.com>
This commit is contained in:
Yug
2020-07-09 20:18:24 +05:30
committed by mergify[bot]
parent 8dc4ab6b1b
commit 1490daed7e
26 changed files with 186 additions and 114 deletions

View File

@ -36,6 +36,15 @@ import (
"k8s.io/utils/mount"
)
// enum defining logging levels.
const (
Default klog.Level = iota + 1
Useful
Extended
Debug
Trace
)
// RoundOffVolSize rounds up given quantity upto chunks of MiB/GiB
func RoundOffVolSize(size int64) int64 {
size = RoundOffBytes(size)
@ -337,3 +346,75 @@ func contains(s []string, key string) bool {
return false
}
// DefaultLog helps in logging with klog.level 1
func DefaultLog(message string, args ...interface{}) {
logMessage := fmt.Sprintf(message, args...)
// If logging is disabled, don't evaluate the arguments
if klog.V(Default).Enabled() {
klog.InfoDepth(1, logMessage)
}
}
// UsefulLog helps in logging with klog.level 2
func UsefulLog(ctx context.Context, message string, args ...interface{}) {
logMessage := fmt.Sprintf(Log(ctx, message), args...)
// If logging is disabled, don't evaluate the arguments
if klog.V(Useful).Enabled() {
klog.InfoDepth(1, logMessage)
}
}
// ExtendedLogMsg helps in logging a message with klog.level 3
func ExtendedLogMsg(message string, args ...interface{}) {
logMessage := fmt.Sprintf(message, args...)
// If logging is disabled, don't evaluate the arguments
if klog.V(Extended).Enabled() {
klog.InfoDepth(1, logMessage)
}
}
// ExtendedLog helps in logging with klog.level 3
func ExtendedLog(ctx context.Context, message string, args ...interface{}) {
logMessage := fmt.Sprintf(Log(ctx, message), args...)
// If logging is disabled, don't evaluate the arguments
if klog.V(Extended).Enabled() {
klog.InfoDepth(1, logMessage)
}
}
// DebugLogMsg helps in logging a message with klog.level 4
func DebugLogMsg(message string, args ...interface{}) {
logMessage := fmt.Sprintf(message, args...)
// If logging is disabled, don't evaluate the arguments
if klog.V(Debug).Enabled() {
klog.InfoDepth(1, logMessage)
}
}
// DebugLog helps in logging with klog.level 4
func DebugLog(ctx context.Context, message string, args ...interface{}) {
logMessage := fmt.Sprintf(Log(ctx, message), args...)
// If logging is disabled, don't evaluate the arguments
if klog.V(Debug).Enabled() {
klog.InfoDepth(1, logMessage)
}
}
// TraceLogMsg helps in logging a message with klog.level 5
func TraceLogMsg(message string, args ...interface{}) {
logMessage := fmt.Sprintf(message, args...)
// If logging is disabled, don't evaluate the arguments
if klog.V(Trace).Enabled() {
klog.InfoDepth(1, logMessage)
}
}
// TraceLog helps in logging with klog.level 5
func TraceLog(ctx context.Context, message string, args ...interface{}) {
logMessage := fmt.Sprintf(Log(ctx, message), args...)
// If logging is disabled, don't evaluate the arguments
if klog.V(Trace).Enabled() {
klog.InfoDepth(1, logMessage)
}
}