8d797a4a by astaxie

file the static filter

1 parent 10db97b1
Showing 1 changed file with 24 additions and 4 deletions
...@@ -72,11 +72,31 @@ var ( ...@@ -72,11 +72,31 @@ var (
72 "SetSecureCookie", "XsrfToken", "CheckXsrfCookie", "XsrfFormHtml", 72 "SetSecureCookie", "XsrfToken", "CheckXsrfCookie", "XsrfFormHtml",
73 "GetControllerAndAction"} 73 "GetControllerAndAction"}
74 74
75 url_placeholder = "{{placeholder}}" 75 url_placeholder = "{{placeholder}}"
76 76 DefaultLogFilter FilterHandler = &logFilter{}
77 FilterRouterLog func(*beecontext.Context) bool
78 ) 77 )
79 78
79 type FilterHandler interface {
80 Filter(*beecontext.Context) bool
81 }
82
83 // default log filter static file will not show
84 type logFilter struct {
85 }
86
87 func (l *logFilter) Filter(ctx *beecontext.Context) bool {
88 requestPath := path.Clean(ctx.Input.Request.URL.Path)
89 if requestPath == "/favicon.ico" || requestPath == "/robots.txt" {
90 return true
91 }
92 for prefix, _ := range StaticDir {
93 if strings.HasPrefix(requestPath, prefix) {
94 return true
95 }
96 }
97 return false
98 }
99
80 // To append a slice's value into "exceptMethod", for controller's methods shouldn't reflect to AutoRouter 100 // To append a slice's value into "exceptMethod", for controller's methods shouldn't reflect to AutoRouter
81 func ExceptMethodAppend(action string) { 101 func ExceptMethodAppend(action string) {
82 exceptMethod = append(exceptMethod, action) 102 exceptMethod = append(exceptMethod, action)
...@@ -815,7 +835,7 @@ Admin: ...@@ -815,7 +835,7 @@ Admin:
815 } else { 835 } else {
816 devinfo = fmt.Sprintf("| % -10s | % -40s | % -16s | % -10s |", r.Method, r.URL.Path, timeend.String(), "notmatch") 836 devinfo = fmt.Sprintf("| % -10s | % -40s | % -16s | % -10s |", r.Method, r.URL.Path, timeend.String(), "notmatch")
817 } 837 }
818 if FilterRouterLog == nil || !FilterRouterLog(context) { 838 if DefaultLogFilter == nil || !DefaultLogFilter.Filter(context) {
819 Debug(devinfo) 839 Debug(devinfo)
820 } 840 }
821 } 841 }
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!