From 824a587eae165d255908f435fbdd637968347d1d Mon Sep 17 00:00:00 2001 From: Henry Camacho Date: Mon, 27 Mar 2017 16:09:25 -0500 Subject: [PATCH] Adding support for config path and config file --- main.go | 10 ++++++++-- rvpn/genericlistener/setup.go | 14 ++++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index 53449ff..7102bea 100644 --- a/main.go +++ b/main.go @@ -19,10 +19,13 @@ import ( ) var ( + logfile = "stdout" + configPath = "./" + configFile = "go-rvpn-server.yaml" + loginfo *log.Logger logdebug *log.Logger logFlags = log.Ldate | log.Lmicroseconds | log.Lshortfile - logfile = "stdout" argWssClientListener string argGenericBinding int argServerBinding string @@ -42,6 +45,9 @@ var ( func init() { flag.StringVar(&logfile, "log", logfile, "Log file (or stdout/stderr; empty for none)") + flag.StringVar(&configPath, "config-path", configPath, "Configuration File Path") + flag.StringVar(&configFile, "config-file", configFile, "Configuration File Name") + } var logoutput io.Writer @@ -71,7 +77,7 @@ func main() { loginfo = log.New(logoutput, "INFO: main: ", logFlags) logdebug = log.New(logoutput, "DEBUG: main:", logFlags) - viper.SetConfigName("go-rvpn-server") + viper.SetConfigName(configPath) viper.AddConfigPath("./") err := viper.ReadInConfig() if err != nil { diff --git a/rvpn/genericlistener/setup.go b/rvpn/genericlistener/setup.go index 6541c3b..c57d333 100644 --- a/rvpn/genericlistener/setup.go +++ b/rvpn/genericlistener/setup.go @@ -1,12 +1,13 @@ package genericlistener import ( + "io" "log" "os" - "runtime" ) var ( + //Logoutput -- passing the output writer from main loginfo *log.Logger logdebug *log.Logger logFlags = log.Ldate | log.Lmicroseconds | log.Lshortfile @@ -16,8 +17,13 @@ var ( func init() { loginfo = log.New(os.Stdout, "INFO: genericlistener: ", logFlags) logdebug = log.New(os.Stdout, "DEBUG: genericlistener:", logFlags) - pc, _, _, _ := runtime.Caller(0) - loginfo.Println(runtime.FuncForPC(pc).Name()) - connectionID = 0 } + +//InitLogging -- after main sets up output, it will init all packages InitLogging +//I am sure I am doing this wrong, but I could not find a way to have package level +//logging with the flags I wanted and the ability to run lumberjack file management +func InitLogging(logoutput io.Writer) { + loginfo.SetOutput(logoutput) + +}