mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 10:33:35 +00:00
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:
@ -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)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user