diff --git a/admin/admin.go b/admin/admin.go
index feda89c..de01598 100644
--- a/admin/admin.go
+++ b/admin/admin.go
@@ -21,3 +21,26 @@ along with Mapo. If not, see .
Package admin implements the API for Mapo's administration components.
*/
package admin
+
+import (
+ "gconf/conf"
+)
+
+/*
+GlobalConfiguration, il oggetto globale per l'accesso ai dati contenuti nel
+file di configurazione.
+*/
+var GlobalConfiguration *conf.ConfigFile
+
+/*
+ReadConfiguration, attiva il GlobalConfiguration.
+*/
+func ReadConfiguration(filepath string) error {
+
+ c, err := conf.ReadConfigFile(filepath)
+ if err == nil {
+ GlobalConfiguration = c
+ }
+
+ return err
+}
diff --git a/log/.log.go.swo b/log/.log.go.swo
deleted file mode 100644
index 31bbc07..0000000
Binary files a/log/.log.go.swo and /dev/null differ
diff --git a/log/log.go b/log/log.go
index b39a22f..c196ed0 100644
--- a/log/log.go
+++ b/log/log.go
@@ -42,7 +42,13 @@ var l logger
// SetLevel sets the output level for the global logger
func SetLevel(level int) {
- l.level = level
+
+ if level <= DEBUG {
+ l.level = level
+ return
+ }
+
+ panic(fmt.Sprintf("Unknown log level %v", level))
}
func print(level int, format string, v ...interface{}) {
diff --git a/mapo.go b/mapo.go
index 5c2790b..da1d4cd 100644
--- a/mapo.go
+++ b/mapo.go
@@ -20,17 +20,47 @@ along with Mapo. If not, see .
package main
import (
- "mapo/log"
+ "github.com/maponet/utils/log"
+ "github.com/maponet/utils/conf"
+
+ "flag"
)
func main() {
+ var err error
+
+ // set config defaults
+ conf.Set("logLevel", "INFO")
+
// parse flags
+ var flagLogLevel, flagConfPath string
+ flag.StringVar(&flagConfPath, "conf", "/etc/mapo/mapo.conf", "set path to configuration file")
+ flag.StringVar(&flagLogLevel, "log", "", "set loglevel [ERROR|INFO|DEBUG]")
+ flag.Parse()
+
+ // load config from file
+ confErr := conf.ParseFile(flagConfPath)
- // load config and setup application
- log.SetLevel(log.DEBUG)
- log.Info("Setting log level to DEBUG")
+ // override config settings with command line flags
+ if flagLogLevel != "" {
+ conf.Set("logLevel", flagLogLevel)
+ }
+
+ logLevel, _ := conf.GetString("logLevel")
+ err = log.SetLevel(logLevel)
+ if err != nil {
+ log.Fatal(err.Error())
+ }
log.Info("Starting application")
+ if confErr == nil {
+ log.Info("Loaded configuration file: %s", flagConfPath)
+ } else {
+ log.Error("Can't load config file (%s), using defaults", confErr.Error())
+ }
+ log.Info("Setting log level to: %s", logLevel)
+
+ // setup application
// register with supervisor
log.Info("Joining supervisor")
@@ -50,20 +80,19 @@ func main() {
// inform supervisor that we are up
// for each request
- // check authentication/authorization
-
- // extract request operation
+ // check authentication/authorization
- // extract request arguments
+ // extract request operation
- // pass operation and arguments to api.router
+ // extract request arguments
- // find function mapped to operation
+ // pass operation and arguments to api.router
- // call function with arguments
+ // find function mapped to operation
- // return result to user
+ // call function with arguments
+ // return result to user
// close on signal
log.Info("Closing application")