change default to empty string

This commit is contained in:
berlin2123 2025-03-05 19:15:19 +08:00 committed by GitHub
parent ac9b121314
commit 2d6712aed2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 7 deletions

View File

@ -128,7 +128,7 @@ type ServerCommonConf struct {
// LogDurationTypes specifies the types of connection names for which the // LogDurationTypes specifies the types of connection names for which the
// duration will be logged. If set to 'ssh,rdp', it will log the duration // 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 // 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"` LogDurationTypes string `ini:"log_duration_types" json:"log_duration_types"`
// DetailedErrorsToClient defines whether to send the specific error (with // DetailedErrorsToClient defines whether to send the specific error (with
// debug info) to frpc. By default, this value is true. // debug info) to frpc. By default, this value is true.
@ -215,7 +215,7 @@ func GetDefaultServerConf() ServerCommonConf {
DashboardAddr: "0.0.0.0", DashboardAddr: "0.0.0.0",
LogFile: "console", LogFile: "console",
LogWay: "console", LogWay: "console",
LogDurationTypes: "ssh,rdp", LogDurationTypes: "",
DetailedErrorsToClient: true, DetailedErrorsToClient: true,
TCPMux: true, TCPMux: true,
AllowPorts: make(map[int]struct{}), AllowPorts: make(map[int]struct{}),

View File

@ -113,7 +113,7 @@ type LogConfig struct {
// DurationTypes specifies the types of connection names for which the // DurationTypes specifies the types of connection names for which the
// duration will be logged. If set to 'ssh,rdp', it will log the duration // 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 // 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"` DurationTypes string `json:"durationtypes,omitempty"`
} }
@ -121,7 +121,7 @@ func (c *LogConfig) Complete() {
c.To = util.EmptyOr(c.To, "console") c.To = util.EmptyOr(c.To, "console")
c.Level = util.EmptyOr(c.Level, "info") c.Level = util.EmptyOr(c.Level, "info")
c.MaxDays = util.EmptyOr(c.MaxDays, 3) c.MaxDays = util.EmptyOr(c.MaxDays, 3)
c.DurationTypes = util.EmptyOr(c.DurationTypes, "ssh,rdp") c.DurationTypes = util.EmptyOr(c.DurationTypes, "")
} }
type HTTPPluginOptions struct { type HTTPPluginOptions struct {

View File

@ -63,6 +63,7 @@ type Proxy interface {
type BaseProxy struct { type BaseProxy struct {
name string name string
logDuration bool
rc *controller.ResourceController rc *controller.ResourceController
listeners []net.Listener listeners []net.Listener
usedPortsNum int usedPortsNum int
@ -272,7 +273,7 @@ func (pxy *BaseProxy) handleUserTCPConnection(userConn net.Conn) {
metrics.Server.AddTrafficOut(name, proxyType, outCount) metrics.Server.AddTrafficOut(name, proxyType, outCount)
// Log the duration of connection. // Log the duration of connection.
if IsTheTypeToLog(serverCfg.Log.DurationTypes, name) { if pxy.logDuration {
endtime := time.Now().UnixNano() / 1000000 // time in microseconds endtime := time.Now().UnixNano() / 1000000 // time in microseconds
connectionDuration := endtime - startime connectionDuration := endtime - startime
xl.Debugf("join connection closed, it remains [%d]ms, workConn(l[%s] r[%s]) userConn(l[%s] r[%s])", connectionDuration, 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. // 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") { if strings.Contains(logDurationTypes, "all") {
xl.Infof("The duration of each connection through this Proxy will be logged.")
return true return true
} }
thestrlist := strings.Split(logDurationTypes, ",") thestrlist := strings.Split(logDurationTypes, ",")
for i := 0; i < len(thestrlist); i++ { 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 return true
} }
} }
@ -320,6 +323,7 @@ func NewProxy(ctx context.Context, options *Options) (pxy Proxy, err error) {
basePxy := BaseProxy{ basePxy := BaseProxy{
name: configurer.GetBaseConfig().Name, name: configurer.GetBaseConfig().Name,
logDuration: IsTheTypeToLog(options.ServerCfg.Log.DurationTypes, configurer.GetBaseConfig().Name, xl),
rc: options.ResourceController, rc: options.ResourceController,
listeners: make([]net.Listener, 0), listeners: make([]net.Listener, 0),
poolCount: options.PoolCount, poolCount: options.PoolCount,