Adding support for config path and config file
This commit is contained in:
parent
a528352e28
commit
824a587eae
10
main.go
10
main.go
|
@ -19,10 +19,13 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
logfile = "stdout"
|
||||||
|
configPath = "./"
|
||||||
|
configFile = "go-rvpn-server.yaml"
|
||||||
|
|
||||||
loginfo *log.Logger
|
loginfo *log.Logger
|
||||||
logdebug *log.Logger
|
logdebug *log.Logger
|
||||||
logFlags = log.Ldate | log.Lmicroseconds | log.Lshortfile
|
logFlags = log.Ldate | log.Lmicroseconds | log.Lshortfile
|
||||||
logfile = "stdout"
|
|
||||||
argWssClientListener string
|
argWssClientListener string
|
||||||
argGenericBinding int
|
argGenericBinding int
|
||||||
argServerBinding string
|
argServerBinding string
|
||||||
|
@ -42,6 +45,9 @@ var (
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
flag.StringVar(&logfile, "log", logfile, "Log file (or stdout/stderr; empty for none)")
|
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
|
var logoutput io.Writer
|
||||||
|
@ -71,7 +77,7 @@ func main() {
|
||||||
loginfo = log.New(logoutput, "INFO: main: ", logFlags)
|
loginfo = log.New(logoutput, "INFO: main: ", logFlags)
|
||||||
logdebug = log.New(logoutput, "DEBUG: main:", logFlags)
|
logdebug = log.New(logoutput, "DEBUG: main:", logFlags)
|
||||||
|
|
||||||
viper.SetConfigName("go-rvpn-server")
|
viper.SetConfigName(configPath)
|
||||||
viper.AddConfigPath("./")
|
viper.AddConfigPath("./")
|
||||||
err := viper.ReadInConfig()
|
err := viper.ReadInConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
package genericlistener
|
package genericlistener
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
//Logoutput -- passing the output writer from main
|
||||||
loginfo *log.Logger
|
loginfo *log.Logger
|
||||||
logdebug *log.Logger
|
logdebug *log.Logger
|
||||||
logFlags = log.Ldate | log.Lmicroseconds | log.Lshortfile
|
logFlags = log.Ldate | log.Lmicroseconds | log.Lshortfile
|
||||||
|
@ -16,8 +17,13 @@ var (
|
||||||
func init() {
|
func init() {
|
||||||
loginfo = log.New(os.Stdout, "INFO: genericlistener: ", logFlags)
|
loginfo = log.New(os.Stdout, "INFO: genericlistener: ", logFlags)
|
||||||
logdebug = log.New(os.Stdout, "DEBUG: genericlistener:", logFlags)
|
logdebug = log.New(os.Stdout, "DEBUG: genericlistener:", logFlags)
|
||||||
pc, _, _, _ := runtime.Caller(0)
|
|
||||||
loginfo.Println(runtime.FuncForPC(pc).Name())
|
|
||||||
|
|
||||||
connectionID = 0
|
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)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue