diff --git a/conf.ini b/conf.ini new file mode 100644 index 0000000..1cfd8c7 --- /dev/null +++ b/conf.ini @@ -0,0 +1,7 @@ +[default] +cookiesecret = some secrete phrase +mapohome = /mapo/root/folder + +[googleoauth] +clientid = client_id +clientsecret = client_secret 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 deleted file mode 100644 index b39a22f..0000000 --- a/log/log.go +++ /dev/null @@ -1,81 +0,0 @@ -/* -Copyright 2013 Petru Ciobanu, Francesco Paglia, Lorenzo Pierfederici - -This file is part of Mapo. - -Mapo is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 2 of the License, or -(at your option) any later version. - -Mapo is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Mapo. If not, see . -*/ - -/* -Package log contains a simple multi-level logger. -*/ -package log - -import ( - "fmt" - "time" -) - -// Available log levels -const ( - ERROR = iota - INFO - DEBUG -) - -type logger struct { - level int -} - -var l logger - -// SetLevel sets the output level for the global logger -func SetLevel(level int) { - l.level = level -} - -func print(level int, format string, v ...interface{}) { - if level <= l.level { - var msgType string - - switch level { - case ERROR: - msgType = "ERROR" - case INFO: - msgType = "INFO" - case DEBUG: - msgType = "DEBUG" - } - - msg := fmt.Sprintf(format, v...) - t := time.Now().Format(time.RFC1123) - fmt.Printf("%s [%s]: %s\n", t, msgType, msg) - - } -} - -// Error logs a message at "ERROR" level -func Error(format string, v ...interface{}) { - print(ERROR, format, v...) -} - -// Info logs a message at "INFO" level -func Info(format string, v ...interface{}) { - print(INFO, format, v...) -} - -// Debug logs a message at "DEBUG" level -func Debug(format string, v ...interface{}) { - print(DEBUG, format, v...) -} diff --git a/mapo.go b/mapo.go index 5c2790b..abee75c 100644 --- a/mapo.go +++ b/mapo.go @@ -20,15 +20,46 @@ along with Mapo. If not, see . package main import ( - "mapo/log" + "github.com/maponet/utils/log" + "github.com/maponet/utils/conf" + + "flag" ) func main() { - // parse flags + + /* + parse flags + + In some situation we will pass path to configuration file as a command line + value. This meaning that for first off all we need to define and parse all flags. + The only flag that we required on this step is only conf flag ... But we + can't distribute code with same functionality along file or files. + */ + var logLevel = log.FlagLevel("log") + var confFilePath = flag.String("conf", "./conf.ini", "set path to configuration file") + flag.Parse() // load config and setup application - log.SetLevel(log.DEBUG) - log.Info("Setting log level to DEBUG") + err := conf.ParseConfigFile(*confFilePath) + if err != nil { + log.Error("%v", err) + return + } + + // setup configuration value passed as command line arguments + if len(*logLevel) > 0 { + conf.GlobalConfiguration.AddOption("default", "loglevel", *logLevel) + } + + // setup application + + // set log level + value, _ := conf.GlobalConfiguration.GetString("default", "loglevel") + if err := log.SetLevelString(value); err != nil { + log.Error("%v", err) + return + } log.Info("Starting application") @@ -64,7 +95,6 @@ func main() { // return result to user - // close on signal log.Info("Closing application") }