|
@@ -6,6 +6,8 @@ package main
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
"flag"
|
|
"flag"
|
|
|
|
|
+ "fmt"
|
|
|
|
|
+ "io/ioutil"
|
|
|
"time"
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/coredhcp/coredhcp"
|
|
"github.com/coredhcp/coredhcp"
|
|
@@ -21,9 +23,26 @@ import (
|
|
|
var (
|
|
var (
|
|
|
flagLogFile = flag.String("logfile", "", "Name of the log file to append to. Default: stdout/stderr only")
|
|
flagLogFile = flag.String("logfile", "", "Name of the log file to append to. Default: stdout/stderr only")
|
|
|
flagLogNoStdout = flag.Bool("nostdout", false, "Disable logging to stdout/stderr")
|
|
flagLogNoStdout = flag.Bool("nostdout", false, "Disable logging to stdout/stderr")
|
|
|
- flagDebug = flag.Bool("debug", false, "Enable debug output")
|
|
|
|
|
|
|
+ flagLogLevel = flag.String("loglevel", "info", fmt.Sprintf("Log level. One of %v", getLogLevels()))
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
+var logLevels = map[string]func(*logrus.Logger){
|
|
|
|
|
+ "none": func(l *logrus.Logger) { l.SetOutput(ioutil.Discard) },
|
|
|
|
|
+ "debug": func(l *logrus.Logger) { l.SetLevel(logrus.DebugLevel) },
|
|
|
|
|
+ "info": func(l *logrus.Logger) { l.SetLevel(logrus.InfoLevel) },
|
|
|
|
|
+ "warning": func(l *logrus.Logger) { l.SetLevel(logrus.WarnLevel) },
|
|
|
|
|
+ "error": func(l *logrus.Logger) { l.SetLevel(logrus.ErrorLevel) },
|
|
|
|
|
+ "fatal": func(l *logrus.Logger) { l.SetLevel(logrus.FatalLevel) },
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func getLogLevels() []string {
|
|
|
|
|
+ var levels []string
|
|
|
|
|
+ for k := range logLevels {
|
|
|
|
|
+ levels = append(levels, k)
|
|
|
|
|
+ }
|
|
|
|
|
+ return levels
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
var desiredPlugins = []*plugins.Plugin{
|
|
var desiredPlugins = []*plugins.Plugin{
|
|
|
{{range $plugin := .}}
|
|
{{range $plugin := .}}
|
|
|
{{$import := importname $plugin}}&{{if eq $import "range"}}rangepl{{else}}{{$import}}{{end}}.Plugin,
|
|
{{$import := importname $plugin}}&{{if eq $import "range"}}rangepl{{else}}{{$import}}{{end}}.Plugin,
|
|
@@ -33,10 +52,12 @@ var desiredPlugins = []*plugins.Plugin{
|
|
|
func main() {
|
|
func main() {
|
|
|
flag.Parse()
|
|
flag.Parse()
|
|
|
log := logger.GetLogger("main")
|
|
log := logger.GetLogger("main")
|
|
|
- if *flagDebug {
|
|
|
|
|
- log.Logger.SetLevel(logrus.DebugLevel)
|
|
|
|
|
- log.Infof("Enabled debug logging")
|
|
|
|
|
|
|
+ fn, ok := logLevels[*flagLogLevel]
|
|
|
|
|
+ if !ok {
|
|
|
|
|
+ log.Fatalf("Invalid log level '%s'. Valid log levels are %v", *flagLogLevel, getLogLevels())
|
|
|
}
|
|
}
|
|
|
|
|
+ fn(log.Logger)
|
|
|
|
|
+ log.Infof("Setting log level to '%s'", *flagLogLevel)
|
|
|
if *flagLogFile != "" {
|
|
if *flagLogFile != "" {
|
|
|
log.Infof("Logging to file %s", *flagLogFile)
|
|
log.Infof("Logging to file %s", *flagLogFile)
|
|
|
logger.WithFile(log, *flagLogFile)
|
|
logger.WithFile(log, *flagLogFile)
|