Browse Source

feat:日志过滤

wangshan 3 years ago
parent
commit
95a3497b55

+ 18 - 1
src/jfw/filter/filter.go

@@ -2,15 +2,32 @@ package filter
 
 import (
 	"jfw/jyutil"
-	//"jfw/jyutil"
 	"net/http"
+	"qfw/util"
+	fs "qfw/util/fsnotify"
+	"regexp"
 	"time"
 
 	"github.com/go-xweb/xweb"
 )
 
+var RouteConf struct {
+	ExcludeRoute []string
+}
+var ExcludeUrl []*regexp.Regexp
+
 func init() {
 	xweb.AddFilter(&Filter{})
+	//日志过滤 路由集合
+	go fs.FSNotifyFUNC("sword->%s", "./route.json", true, func() {
+		util.ReadConfig("./route.json", &RouteConf)
+		if len(RouteConf.ExcludeRoute) > 0 {
+			ExcludeUrl = []*regexp.Regexp{}
+			for _, v := range RouteConf.ExcludeRoute {
+				ExcludeUrl = append(ExcludeUrl, regexp.MustCompile(util.ObjToString(v)))
+			}
+		}
+	})
 	time.AfterFunc(1*time.Minute, SaveLogTask)
 }
 

+ 7 - 0
src/jfw/filter/logfilter.go

@@ -64,6 +64,13 @@ func SaveLogTask() {
 }
 
 func (l *logFilter) addLog() {
+	for _, v := range ExcludeUrl {
+		// log.Println(l.R.URL.Path, "--l.R.URL.Path:", v.MatchString(l.R.URL.Path))
+		// 过滤无意义路由日志
+		if v.MatchString(l.R.URL.Path) {
+			return
+		}
+	}
 	timeNow := time.Now()
 	agent := l.R.Header.Get("user-agent")
 	ref := l.R.Referer()

+ 18 - 0
src/jfw/modules/app/src/app/filter/filter.go

@@ -2,13 +2,31 @@ package filter
 
 import (
 	"net/http"
+	"qfw/util"
+	fs "qfw/util/fsnotify"
+	"regexp"
 	"time"
 
 	"github.com/go-xweb/xweb"
 )
 
+var RouteConf struct {
+	ExcludeRoute []string
+}
+var ExcludeUrl []*regexp.Regexp
+
 func init() {
 	xweb.AddFilter(&Filter{})
+	//日志过滤 路由集合
+	go fs.FSNotifyFUNC("app->%s", "./route.json", true, func() {
+		util.ReadConfig("./route.json", &RouteConf)
+		if len(RouteConf.ExcludeRoute) > 0 {
+			ExcludeUrl = []*regexp.Regexp{}
+			for _, v := range RouteConf.ExcludeRoute {
+				ExcludeUrl = append(ExcludeUrl, regexp.MustCompile(util.ObjToString(v)))
+			}
+		}
+	})
 	time.AfterFunc(1*time.Minute, SaveLogTask)
 }
 

+ 7 - 0
src/jfw/modules/app/src/app/filter/logfilter.go

@@ -52,6 +52,13 @@ func SaveLogTask() {
 }
 
 func (l *logFilter) addLog() {
+	for _, v := range ExcludeUrl {
+		// log.Println(l.R.URL.Path, "--l.R.URL.Path:", v.MatchString(l.R.URL.Path))
+		// 过滤无意义路由日志
+		if v.MatchString(l.R.URL.Path) {
+			return
+		}
+	}
 	timeNow := time.Now()
 	agent := l.R.Header.Get("user-agent")
 	s_url := l.R.RequestURI

+ 9 - 0
src/jfw/modules/app/src/route.json

@@ -0,0 +1,9 @@
+{
+	"excludeRoute":[
+		"^/jyapp/free/(.*)",
+		"^/jyapp/free/checkUpdate",
+		"^/jyapp/free/config",
+		"^/jyapp/free/login",
+		"^/jyapp/frontPage/collection/sess/(.*)"
+	]
+}

+ 17 - 0
src/route.json

@@ -0,0 +1,17 @@
+{
+	"excludeRoute":[
+		"^/front/share/(.*)",
+		"^/front/landpage/captcha",
+		"^/front/hasSign",
+		"^/qr",
+		"^/front/getLoginNum/(.*)",
+		"^/front/aboutus.html",
+		"^/front/downloadJyApp/qr",
+		"^/share/encrypt",
+		"^/front/rediskw",
+		"^/front/getLoginNum/(.*)",
+		"^/notin/page",
+		"^/front/ajaxPolling",
+		"^/checkDateForAjax"
+	]
+}