summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crawler/config.go7
-rw-r--r--crawler/log.go17
-rw-r--r--crawler/main.go11
3 files changed, 22 insertions, 13 deletions
diff --git a/crawler/config.go b/crawler/config.go
index 329c41b..2eb7d03 100644
--- a/crawler/config.go
+++ b/crawler/config.go
@@ -1,7 +1,6 @@
package main
import (
- log "github.com/Sirupsen/logrus"
"github.com/spf13/viper"
)
@@ -54,11 +53,7 @@ func (c *Config) parseConfig(configFile string) {
// Reads the config
err := viper.ReadInConfig()
if err != nil {
- log.WithFields(
- log.Fields{
- "error": err.Error(),
- },
- ).Fatal("Fatal error config file")
+ Fatal(err, "Config: Error parsing config file.")
}
c.setsConfig()
diff --git a/crawler/log.go b/crawler/log.go
index 4b9f374..3a6afa0 100644
--- a/crawler/log.go
+++ b/crawler/log.go
@@ -1,11 +1,26 @@
package main
import (
+ "flag"
+
log "github.com/Sirupsen/logrus"
)
+// global config, gets overwritten by main
+var _conf Config
+
func init() {
- log.SetLevel(log.DebugLevel)
+ // we need to parse the config because of log level setting
+ configFile := flag.String("config", "", "path to config file")
+ flag.Parse()
+
+ _conf.parseConfig(*configFile)
+
+ if _conf.Debug {
+ log.SetLevel(log.DebugLevel)
+ } else {
+ log.SetLevel(log.WarnLevel)
+ }
}
func Fatal(err error, msg string) {
diff --git a/crawler/main.go b/crawler/main.go
index 69f9638..8727443 100644
--- a/crawler/main.go
+++ b/crawler/main.go
@@ -2,7 +2,6 @@ package main
import (
"encoding/json"
- "flag"
"fmt"
"time"
@@ -54,11 +53,11 @@ func main() {
var err error
- configFile := flag.String("config", "", "path to config file")
- flag.Parse()
-
- app := App{Config: &Config{}}
- app.Config.parseConfig(*configFile)
+ // copy global config to avoid woring with globals
+ _own_config := _conf
+ app := App{Config: &_own_config}
+ // overwrite the global
+ _conf = Config{}
app.Now = time.Now().Unix()