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 (
|
||||
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 {
|
||||
|
|
|
@ -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)
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue