config: added config logflags

This commit is contained in:
nadoo 2021-07-17 23:43:22 +08:00
parent 56277acb7d
commit 9af5ca9baf
4 changed files with 11 additions and 3 deletions

View File

@ -142,6 +142,8 @@ glider 0.15.0 usage:
source ip or source interface
-listen value
listen url, format: SCHEME://[USER|METHOD:PASSWORD@][HOST]:PORT?PARAMS
-logflags int
log flags, do not change it if you do not know what it is, ref: https://pkg.go.dev/log#pkg-constants (default 19)
-maxfailures int
max failures to change forwarder status to disabled (default 3)
-relaytimeout int

View File

@ -16,7 +16,8 @@ var flag = conflag.New()
// Config is global config struct.
type Config struct {
Verbose bool
Verbose bool
LogFlags int
Listens []string
@ -40,6 +41,7 @@ func parseConfig() *Config {
flag.SetOutput(os.Stdout)
flag.BoolVar(&conf.Verbose, "verbose", false, "verbose mode")
flag.IntVar(&conf.LogFlags, "logflags", 19, "log flags, do not change it if you do not know what it is, ref: https://pkg.go.dev/log#pkg-constants")
flag.StringSliceUniqVar(&conf.Listens, "listen", nil, "listen url, format: SCHEME://[USER|METHOD:PASSWORD@][HOST]:PORT?PARAMS")
flag.StringSliceUniqVar(&conf.Forwards, "forward", nil, "forward url, format: SCHEME://[USER|METHOD:PASSWORD@][HOST]:PORT?PARAMS[,SCHEME://[USER|METHOD:PASSWORD@][HOST]:PORT?PARAMS]")
@ -81,6 +83,7 @@ func parseConfig() *Config {
// setup a log func
if conf.Verbose {
log.SetFlag(conf.LogFlags)
log.F = log.Debugf
}

View File

@ -8,8 +8,9 @@ import (
// F is the main log function.
var F = func(string, ...interface{}) {}
func init() {
stdlog.SetFlags(stdlog.Flags() | stdlog.Lshortfile)
// SetFlag sets the output flags for the logger.
func SetFlag(flag int) {
stdlog.SetFlags(flag)
}
// Debugf prints debug log.

View File

@ -73,6 +73,8 @@ func (s *TProxy) ListenAndServeUDP() {
return
}
log.F("[tproxyu] listening UDP on %s", s.addr)
var nm sync.Map
buf := make([]byte, proxy.UDPBufSize)