flag.CommandLine.Parse(args[2:])
- var level safcm.LogLevel
- switch *optionLog {
- case "error":
- level = safcm.LogError
- case "info":
- level = safcm.LogInfo
- case "verbose":
- level = safcm.LogVerbose
- case "debug":
- level = safcm.LogDebug
- case "debug2":
- level = safcm.LogDebug2
- case "debug3":
- level = safcm.LogDebug3
- default:
- return fmt.Errorf("invalid -log value %q", *optionLog)
+ level, err := safcm.ParseLogLevel(*optionLog)
+ if err != nil {
+ return fmt.Errorf("-log: %v", err)
}
names := flag.Args()
package safcm
+import (
+ "fmt"
+)
+
// LogLevel controls the number of displayed log messages. Higher levels
// include all messages from lower levels (e.g. LogVerbose includes all
// messages from LogInfo).
// Log all RPC messages
LogDebug3
)
+
+func ParseLogLevel(s string) (LogLevel, error) {
+ var x LogLevel
+ switch s {
+ case "error":
+ x = LogError
+ case "info":
+ x = LogInfo
+ case "verbose":
+ x = LogVerbose
+ case "debug":
+ x = LogDebug
+ case "debug2":
+ x = LogDebug2
+ case "debug3":
+ x = LogDebug3
+ default:
+ return 0, fmt.Errorf("invalid LogLevel %q", s)
+ }
+ return x, nil
+}