mirror of https://github.com/fatedier/frp
				
				
				
			utils/log: support max days of keeping log files
							parent
							
								
									d7797cbd18
								
							
						
					
					
						commit
						c10321ead6
					
				| 
						 | 
				
			
			@ -6,6 +6,7 @@ server_port = 7000
 | 
			
		|||
log_file = ./frpc.log
 | 
			
		||||
# debug, info, warn, error
 | 
			
		||||
log_level = info
 | 
			
		||||
log_max_days = 3
 | 
			
		||||
# for authentication
 | 
			
		||||
auth_token = 123
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,6 +8,7 @@ vhost_http_port = 80
 | 
			
		|||
log_file = ./frps.log
 | 
			
		||||
# debug, info, warn, error
 | 
			
		||||
log_level = info
 | 
			
		||||
log_max_days = 3
 | 
			
		||||
 | 
			
		||||
# ssh is the proxy name, client will use this name and auth_token to connect to server
 | 
			
		||||
[ssh]
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -88,7 +88,7 @@ func main() {
 | 
			
		|||
		client.ServerPort = serverPort
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	log.InitLog(client.LogWay, client.LogFile, client.LogLevel)
 | 
			
		||||
	log.InitLog(client.LogWay, client.LogFile, client.LogLevel, client.LogMaxDays)
 | 
			
		||||
 | 
			
		||||
	// wait until all control goroutine exit
 | 
			
		||||
	var wait sync.WaitGroup
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -90,7 +90,7 @@ func main() {
 | 
			
		|||
		server.BindPort = bindPort
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	log.InitLog(server.LogWay, server.LogFile, server.LogLevel)
 | 
			
		||||
	log.InitLog(server.LogWay, server.LogFile, server.LogLevel, server.LogMaxDays)
 | 
			
		||||
 | 
			
		||||
	l, err := conn.Listen(server.BindAddr, server.BindPort)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
| 
						 | 
				
			
			@ -98,6 +98,7 @@ func main() {
 | 
			
		|||
		os.Exit(1)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// create vhost if VhostHttpPort != 0
 | 
			
		||||
	if server.VhostHttpPort != 0 {
 | 
			
		||||
		vhostListener, err := conn.Listen(server.BindAddr, server.VhostHttpPort)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -28,6 +28,7 @@ var (
 | 
			
		|||
	LogFile           string = "console"
 | 
			
		||||
	LogWay            string = "console"
 | 
			
		||||
	LogLevel          string = "info"
 | 
			
		||||
	LogMaxDays        int64  = 3
 | 
			
		||||
	HeartBeatInterval int64  = 20
 | 
			
		||||
	HeartBeatTimeout  int64  = 90
 | 
			
		||||
)
 | 
			
		||||
| 
						 | 
				
			
			@ -69,6 +70,11 @@ func LoadConf(confFile string) (err error) {
 | 
			
		|||
		LogLevel = tmpStr
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	tmpStr, ok = conf.Get("common", "log_max_days")
 | 
			
		||||
	if ok {
 | 
			
		||||
		LogMaxDays, _ = strconv.ParseInt(tmpStr, 10, 64)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var authToken string
 | 
			
		||||
	tmpStr, ok = conf.Get("common", "auth_token")
 | 
			
		||||
	if ok {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -32,6 +32,7 @@ var (
 | 
			
		|||
	LogFile          string = "console"
 | 
			
		||||
	LogWay           string = "console" // console or file
 | 
			
		||||
	LogLevel         string = "info"
 | 
			
		||||
	LogMaxDays       int64  = 3
 | 
			
		||||
	HeartBeatTimeout int64  = 90
 | 
			
		||||
	UserConnTimeout  int64  = 10
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -82,6 +83,11 @@ func LoadConf(confFile string) (err error) {
 | 
			
		|||
		LogLevel = tmpStr
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	tmpStr, ok = conf.Get("common", "log_max_days")
 | 
			
		||||
	if ok {
 | 
			
		||||
		LogMaxDays, _ = strconv.ParseInt(tmpStr, 10, 64)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// servers
 | 
			
		||||
	for name, section := range conf {
 | 
			
		||||
		if name != "common" {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -113,8 +113,8 @@ func (p *ProxyServer) Start() (err error) {
 | 
			
		|||
				// set timeout
 | 
			
		||||
				time.AfterFunc(time.Duration(UserConnTimeout)*time.Second, func() {
 | 
			
		||||
					p.Lock()
 | 
			
		||||
					defer p.Unlock()
 | 
			
		||||
					element := p.userConnList.Front()
 | 
			
		||||
					p.Unlock()
 | 
			
		||||
					if element == nil {
 | 
			
		||||
						return
 | 
			
		||||
					}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -15,6 +15,7 @@
 | 
			
		|||
package log
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"github.com/astaxie/beego/logs"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -26,24 +27,24 @@ func init() {
 | 
			
		|||
	Log.SetLogFuncCallDepth(Log.GetLogFuncCallDepth() + 1)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func InitLog(logWay string, logFile string, logLevel string) {
 | 
			
		||||
	SetLogFile(logWay, logFile)
 | 
			
		||||
func InitLog(logWay string, logFile string, logLevel string, maxdays int64) {
 | 
			
		||||
	SetLogFile(logWay, logFile, maxdays)
 | 
			
		||||
	SetLogLevel(logLevel)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// logWay: such as file or console
 | 
			
		||||
func SetLogFile(logWay string, logFile string) {
 | 
			
		||||
// logWay: file or console
 | 
			
		||||
func SetLogFile(logWay string, logFile string, maxdays int64) {
 | 
			
		||||
	if logWay == "console" {
 | 
			
		||||
		Log.SetLogger("console", "")
 | 
			
		||||
	} else {
 | 
			
		||||
		Log.SetLogger("file", `{"filename": "`+logFile+`"}`)
 | 
			
		||||
		params := fmt.Sprintf(`{"filename": "%s", "maxdays": %d}`, logFile, maxdays)
 | 
			
		||||
		Log.SetLogger("file", params)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// value: error, warning, info, debug
 | 
			
		||||
func SetLogLevel(logLevel string) {
 | 
			
		||||
	level := 4 // warning
 | 
			
		||||
 | 
			
		||||
	switch logLevel {
 | 
			
		||||
	case "error":
 | 
			
		||||
		level = 3
 | 
			
		||||
| 
						 | 
				
			
			@ -56,7 +57,6 @@ func SetLogLevel(logLevel string) {
 | 
			
		|||
	default:
 | 
			
		||||
		level = 4
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	Log.SetLevel(level)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue