完善访问日志
This commit is contained in:
parent
c57afd6a5d
commit
bba4990ccc
@ -15,6 +15,7 @@ import (
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Application struct {
|
||||
@ -281,6 +282,7 @@ func (that *Application) urlSer(url string) (string, []string) {
|
||||
//访问
|
||||
|
||||
func (that *Application) handler(w http.ResponseWriter, req *http.Request) {
|
||||
nowUnixTime := time.Now()
|
||||
|
||||
_, s := that.urlSer(req.RequestURI)
|
||||
//获取cookie
|
||||
@ -326,10 +328,24 @@ func (that *Application) handler(w http.ResponseWriter, req *http.Request) {
|
||||
|
||||
//跨域设置
|
||||
that.crossDomain(&context)
|
||||
|
||||
defer func() {
|
||||
//是否展示日志
|
||||
if that.WebConnectLog != nil {
|
||||
that.WebConnectLog.Infoln(Substr(context.Req.RemoteAddr, 0, strings.Index(context.Req.RemoteAddr, ":")), context.Req.Method, context.HandlerStr)
|
||||
ipStr := Substr(context.Req.RemoteAddr, 0, strings.Index(context.Req.RemoteAddr, ":"))
|
||||
//负载均衡优化
|
||||
if ipStr == "127.0.0.1" {
|
||||
if req.Header.Get("X-Forwarded-For") != "" {
|
||||
ipStr = req.Header.Get("X-Forwarded-For")
|
||||
} else if req.Header.Get("X-Real-IP") != "" {
|
||||
ipStr = req.Header.Get("X-Real-IP")
|
||||
}
|
||||
}
|
||||
that.WebConnectLog.Infoln(ipStr, context.Req.Method,
|
||||
"time cost:", ObjToFloat64(time.Now().UnixNano()-nowUnixTime.UnixNano())/1000000.00, "ms",
|
||||
"data length:", ObjToFloat64(context.DataSize)/1000.00, "KB", context.HandlerStr)
|
||||
}
|
||||
}()
|
||||
|
||||
//访问拦截true继续false暂停
|
||||
connectListenerLen := len(that.connectListener)
|
||||
|
@ -18,6 +18,7 @@ type Context struct {
|
||||
RespData Map
|
||||
CacheIns
|
||||
SessionIns
|
||||
DataSize int
|
||||
HandlerStr string //复写请求url
|
||||
}
|
||||
|
||||
@ -56,6 +57,7 @@ func (that *Context) Display(statu int, data interface{}) {
|
||||
}
|
||||
|
||||
func (that *Context) View() {
|
||||
|
||||
if that.RespData == nil {
|
||||
return
|
||||
}
|
||||
@ -63,6 +65,8 @@ func (that *Context) View() {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
that.DataSize = len(d)
|
||||
that.RespData = nil
|
||||
that.Resp.Write(d)
|
||||
return
|
||||
}
|
||||
|
BIN
example/bzyy.exe
BIN
example/bzyy.exe
Binary file not shown.
Loading…
Reference in New Issue
Block a user