Skip to content
Permalink
Browse files

Add 'verbose' option to logging minimum information (#275)

This change address #274 to add 'verbose option which outputs
minimum information (for usual runs with a bit information than
'error').
  • Loading branch information...
s1061123 authored and dougbtv committed Mar 7, 2019
1 parent 102cfc3 commit 61416cbd40b9e15d63efc46329c0c9769a532c4d
Showing with 54 additions and 18 deletions.
  1. +15 −2 logging/logging.go
  2. +2 −0 logging/logging_test.go
  3. +37 −16 multus/multus.go
@@ -29,6 +29,7 @@ type Level uint32
const (
PanicLevel Level = iota
ErrorLevel
VerboseLevel
DebugLevel
MaxLevel
UnknownLevel
@@ -44,6 +45,8 @@ func (l Level) String() string {
switch l {
case PanicLevel:
return "panic"
case VerboseLevel:
return "verbose"
case ErrorLevel:
return "error"
case DebugLevel:
@@ -76,6 +79,10 @@ func Debugf(format string, a ...interface{}) {
Printf(DebugLevel, format, a...)
}

func Verbosef(format string, a ...interface{}) {
Printf(VerboseLevel, format, a...)
}

func Errorf(format string, a ...interface{}) error {
Printf(ErrorLevel, format, a...)
return fmt.Errorf(format, a...)
@@ -88,10 +95,16 @@ func Panicf(format string, a ...interface{}) {
Printf(PanicLevel, "========= Stack trace output end ========")
}

func GetLoggingLevel(levelStr string) Level {
func GetLoggingLevel() Level {
return loggingLevel
}

func getLoggingLevel(levelStr string) Level {
switch strings.ToLower(levelStr) {
case "debug":
return DebugLevel
case "verbose":
return VerboseLevel
case "error":
return ErrorLevel
case "panic":
@@ -102,7 +115,7 @@ func GetLoggingLevel(levelStr string) Level {
}

func SetLogLevel(levelStr string) {
level := GetLoggingLevel(levelStr)
level := getLoggingLevel(levelStr)
if level < MaxLevel {
loggingLevel = level
}
@@ -50,6 +50,8 @@ var _ = Describe("logging operations", func() {
Expect(loggingLevel).To(Equal(DebugLevel))
SetLogLevel("Error")
Expect(loggingLevel).To(Equal(ErrorLevel))
SetLogLevel("VERbose")
Expect(loggingLevel).To(Equal(VerboseLevel))
SetLogLevel("PANIC")
Expect(loggingLevel).To(Equal(PanicLevel))
})
@@ -229,18 +229,30 @@ func delegateAdd(exec invoke.Exec, ifName string, delegate *types.DelegateNetCon
}
}

if delegate.ConfListPlugin != false {
result, err := conflistAdd(rt, delegate.Bytes, binDir, exec)
var result cnitypes.Result
var err error
if delegate.ConfListPlugin {
result, err = conflistAdd(rt, delegate.Bytes, binDir, exec)
if err != nil {
return nil, logging.Errorf("Multus: error in invoke Conflist add - %q: %v", delegate.ConfList.Name, err)
}

return result, nil
} else {
result, err = invoke.DelegateAdd(delegate.Conf.Type, delegate.Bytes, exec)
if err != nil {
return nil, logging.Errorf("Multus: error in invoke Delegate add - %q: %v", delegate.Conf.Type, err)
}
}

result, err := invoke.DelegateAdd(delegate.Conf.Type, delegate.Bytes, exec)
if err != nil {
return nil, logging.Errorf("Multus: error in invoke Delegate add - %q: %v", delegate.Conf.Type, err)
if logging.GetLoggingLevel() >= logging.VerboseLevel {
data, _ := json.Marshal(result)
var confName string
if delegate.ConfListPlugin {
confName = delegate.ConfList.Name
} else {
confName = delegate.Conf.Name
}

logging.Verbosef("Add: %s:%s:%s:%s %s", rt.Args[1][1], rt.Args[2][1], confName, rt.IfName, string(data))
}

return result, nil
@@ -252,20 +264,29 @@ func delegateDel(exec invoke.Exec, ifName string, delegateConf *types.DelegateNe
return logging.Errorf("Multus: error in setting CNI_IFNAME")
}

if delegateConf.ConfListPlugin != false {
err := conflistDel(rt, delegateConf.Bytes, binDir, exec)
if err != nil {
return logging.Errorf("Multus: error in invoke Conflist Del - %q: %v", delegateConf.ConfList.Name, err)
if logging.GetLoggingLevel() >= logging.VerboseLevel {
var confName string
if delegateConf.ConfListPlugin {
confName = delegateConf.ConfList.Name
} else {
confName = delegateConf.Conf.Name
}

return err
logging.Verbosef("Del: %s:%s:%s:%s %s", rt.Args[1][1], rt.Args[2][1], confName, rt.IfName, string(delegateConf.Bytes))
}

if err := invoke.DelegateDel(delegateConf.Conf.Type, delegateConf.Bytes, exec); err != nil {
return logging.Errorf("Multus: error in invoke Delegate del - %q: %v", delegateConf.Conf.Type, err)
var err error
if delegateConf.ConfListPlugin {
err = conflistDel(rt, delegateConf.Bytes, binDir, exec)
if err != nil {
return logging.Errorf("Multus: error in invoke Conflist Del - %q: %v", delegateConf.ConfList.Name, err)
}
} else {
if err = invoke.DelegateDel(delegateConf.Conf.Type, delegateConf.Bytes, exec); err != nil {
return logging.Errorf("Multus: error in invoke Delegate del - %q: %v", delegateConf.Conf.Type, err)
}
}

return nil
return err
}

func delPlugins(exec invoke.Exec, argIfname string, delegates []*types.DelegateNetConf, lastIdx int, rt *libcni.RuntimeConf, binDir string) error {

0 comments on commit 61416cb

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.