日志
()
| 14 | |
| 15 | // 日志 |
| 16 | func (this *HTTPRequest) log() { |
| 17 | // 检查全局配置 |
| 18 | if this.nodeConfig != nil && this.nodeConfig.GlobalServerConfig != nil && !this.nodeConfig.GlobalServerConfig.HTTPAccessLog.IsOn { |
| 19 | return |
| 20 | } |
| 21 | |
| 22 | var ref *serverconfigs.HTTPAccessLogRef |
| 23 | if !this.forceLog { |
| 24 | if this.disableLog { |
| 25 | return |
| 26 | } |
| 27 | |
| 28 | // 计算请求时间 |
| 29 | this.requestCost = time.Since(this.requestFromTime).Seconds() |
| 30 | |
| 31 | ref = this.web.AccessLogRef |
| 32 | if ref == nil { |
| 33 | ref = serverconfigs.DefaultHTTPAccessLogRef |
| 34 | } |
| 35 | if !ref.IsOn { |
| 36 | return |
| 37 | } |
| 38 | |
| 39 | if !ref.Match(this.writer.StatusCode()) { |
| 40 | return |
| 41 | } |
| 42 | |
| 43 | if ref.FirewallOnly && this.firewallPolicyId == 0 { |
| 44 | return |
| 45 | } |
| 46 | |
| 47 | // 是否记录499 |
| 48 | if !ref.EnableClientClosed && this.writer.StatusCode() == 499 { |
| 49 | return |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | var addr = this.RawReq.RemoteAddr |
| 54 | var index = strings.LastIndex(addr, ":") |
| 55 | if index > 0 { |
| 56 | addr = addr[:index] |
| 57 | } |
| 58 | |
| 59 | var serverGlobalConfig = this.nodeConfig.GlobalServerConfig |
| 60 | |
| 61 | // 请求Cookie |
| 62 | var cookies = map[string]string{} |
| 63 | var enableCookies = false |
| 64 | if serverGlobalConfig == nil || serverGlobalConfig.HTTPAccessLog.EnableCookies { |
| 65 | enableCookies = true |
| 66 | if ref == nil || ref.ContainsField(serverconfigs.HTTPAccessLogFieldCookie) { |
| 67 | for _, cookie := range this.RawReq.Cookies() { |
| 68 | cookies[cookie.Name] = cookie.Value |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | // 请求Header |
no test coverage detected