From ff9790d2e5c3482ccd6109adac475a9868fc0ab6 Mon Sep 17 00:00:00 2001 From: horus Date: Tue, 20 Feb 2018 17:15:58 +0100 Subject: Refactoring + adds a more granular log level setting. (crawler) --- crawler/init.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 crawler/init.go (limited to 'crawler/init.go') diff --git a/crawler/init.go b/crawler/init.go new file mode 100644 index 0000000..abf212b --- /dev/null +++ b/crawler/init.go @@ -0,0 +1,34 @@ +package main + +import ( + "flag" + "strings" + + log "github.com/Sirupsen/logrus" + //"github.com/spf13/viper" + //flag "github.com/spf13/pflag" +) + +// global config, gets overwritten by main +var _conf Config + +func init() { + // we need to parse the config because of log level setting + configFile := flag.String("config", "", "path to config file") + debug := flag.Bool("debug", false, "debug outputs") + loglevel_f := flag.String("loglevel", "Warn", `sets log level, can be "Warn", "Info" or "Debug"`) + loglevel := strings.ToLower(*loglevel_f) + + flag.Parse() + + if *debug || loglevel == "debug" { + log.SetLevel(log.DebugLevel) + } else if loglevel == "Info" { + log.SetLevel(log.InfoLevel) + } else { + log.SetLevel(log.WarnLevel) + } + + _conf.parseConfig(*configFile) + +} -- cgit v1.2.3