From 2d6712aed269baa785851d06c6df096fa2e36ada Mon Sep 17 00:00:00 2001 From: berlin2123 <68841407+berlin2123@users.noreply.github.com> Date: Wed, 5 Mar 2025 19:15:19 +0800 Subject: [PATCH] change default to empty string --- pkg/config/legacy/server.go | 4 ++-- pkg/config/v1/common.go | 4 ++-- server/proxy/proxy.go | 10 +++++++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/pkg/config/legacy/server.go b/pkg/config/legacy/server.go index 0f659a2d..204bad49 100644 --- a/pkg/config/legacy/server.go +++ b/pkg/config/legacy/server.go @@ -128,7 +128,7 @@ type ServerCommonConf struct { // LogDurationTypes specifies the types of connection names for which the // duration will be logged. If set to 'ssh,rdp', it will log the duration // of connections named 'ssh', 'ssh_1', 'sshname', 'rdp', 'rdp_test1', or - // 'web_my_rdp'. By default, this value is "ssh,rdp". + // 'web_my_rdp'. By default, this value is "". LogDurationTypes string `ini:"log_duration_types" json:"log_duration_types"` // DetailedErrorsToClient defines whether to send the specific error (with // debug info) to frpc. By default, this value is true. @@ -215,7 +215,7 @@ func GetDefaultServerConf() ServerCommonConf { DashboardAddr: "0.0.0.0", LogFile: "console", LogWay: "console", - LogDurationTypes: "ssh,rdp", + LogDurationTypes: "", DetailedErrorsToClient: true, TCPMux: true, AllowPorts: make(map[int]struct{}), diff --git a/pkg/config/v1/common.go b/pkg/config/v1/common.go index f8769def..861919d9 100644 --- a/pkg/config/v1/common.go +++ b/pkg/config/v1/common.go @@ -113,7 +113,7 @@ type LogConfig struct { // DurationTypes specifies the types of connection names for which the // duration will be logged. If set to 'ssh,rdp', it will log the duration // of connections named 'ssh', 'ssh_1', 'sshname', 'rdp', 'rdp_test1', or - // 'web_my_rdp'. By default, this value is "ssh,rdp". + // 'web_my_rdp'. By default, this value is "". DurationTypes string `json:"durationtypes,omitempty"` } @@ -121,7 +121,7 @@ func (c *LogConfig) Complete() { c.To = util.EmptyOr(c.To, "console") c.Level = util.EmptyOr(c.Level, "info") c.MaxDays = util.EmptyOr(c.MaxDays, 3) - c.DurationTypes = util.EmptyOr(c.DurationTypes, "ssh,rdp") + c.DurationTypes = util.EmptyOr(c.DurationTypes, "") } type HTTPPluginOptions struct { diff --git a/server/proxy/proxy.go b/server/proxy/proxy.go index 68baa274..dd944e3c 100644 --- a/server/proxy/proxy.go +++ b/server/proxy/proxy.go @@ -63,6 +63,7 @@ type Proxy interface { type BaseProxy struct { name string + logDuration bool rc *controller.ResourceController listeners []net.Listener usedPortsNum int @@ -272,7 +273,7 @@ func (pxy *BaseProxy) handleUserTCPConnection(userConn net.Conn) { metrics.Server.AddTrafficOut(name, proxyType, outCount) // Log the duration of connection. - if IsTheTypeToLog(serverCfg.Log.DurationTypes, name) { + if pxy.logDuration { endtime := time.Now().UnixNano() / 1000000 // time in microseconds connectionDuration := endtime - startime xl.Debugf("join connection closed, it remains [%d]ms, workConn(l[%s] r[%s]) userConn(l[%s] r[%s])", connectionDuration, @@ -285,13 +286,15 @@ func (pxy *BaseProxy) handleUserTCPConnection(userConn net.Conn) { } // Check Duration should be loged or not. True: while connection name contain a string in logDurationTypes. -func IsTheTypeToLog(logDurationTypes string, name string) bool { +func IsTheTypeToLog(logDurationTypes string, name string, xl *xlog.Logger) bool { if strings.Contains(logDurationTypes, "all") { + xl.Infof("The duration of each connection through this Proxy will be logged.") return true } thestrlist := strings.Split(logDurationTypes, ",") for i := 0; i < len(thestrlist); i++ { - if strings.Contains(name, thestrlist[i]) { + if (thestrlist[i]!="") && strings.Contains(name, thestrlist[i]) { + xl.Infof("The duration of each connection through this Proxy will be logged.") return true } } @@ -320,6 +323,7 @@ func NewProxy(ctx context.Context, options *Options) (pxy Proxy, err error) { basePxy := BaseProxy{ name: configurer.GetBaseConfig().Name, + logDuration: IsTheTypeToLog(options.ServerCfg.Log.DurationTypes, configurer.GetBaseConfig().Name, xl), rc: options.ResourceController, listeners: make([]net.Listener, 0), poolCount: options.PoolCount,