-
Notifications
You must be signed in to change notification settings - Fork 0
/
accesslog.go
75 lines (67 loc) · 3.55 KB
/
accesslog.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package types
// The bunch of interfaces are used to print the access log in format designed by users.
// Access log format consists of three parts, which are "RequestInfoFormat", "RequestHeaderFormat"
// and "ResponseHeaderFormat", also you can get details by reading "AccessLogDetails.md".
// AccessLog is a log object that used to log the access info.
type AccessLog interface {
// Log write the access info.
// The "reqHeaders" contains the request header's information, "respHeader" contains the response header's information
// and "requestInfo" contains some request information
Log(reqHeaders HeaderMap, respHeaders HeaderMap, requestInfo RequestInfo)
}
// AccessLogFilter is a filter of access log to do some filters to access log info
type AccessLogFilter interface {
// Decide can make a decision about how to filter the request headers and requestInfo
Decide(reqHeaders HeaderMap, requestInfo RequestInfo) bool
}
// AccessLogFormatter is a object that format the request info to string
type AccessLogFormatter interface {
// Format makes the request headers, response headers and request info to string for printing according to log formatter
Format(buf IoBuffer, reqHeaders HeaderMap, respHeaders HeaderMap, requestInfo RequestInfo)
}
// The identification of a request info's content
const (
LogStartTime string = "StartTime"
LogRequestReceivedDuration string = "RequestReceivedDuration"
LogResponseReceivedDuration string = "ResponseReceivedDuration"
LogRequestFinishedDuration string = "RequestFinishedDuration"
LogBytesSent string = "BytesSent"
LogBytesReceived string = "BytesReceived"
LogProtocol string = "Protocol"
LogResponseCode string = "ResponseCode"
LogDuration string = "Duration"
LogResponseFlag string = "ResponseFlag"
LogUpstreamLocalAddress string = "UpstreamLocalAddress"
LogDownstreamLocalAddress string = "DownstreamLocalAddress"
LogDownstreamRemoteAddress string = "DownstreamRemoteAddress"
LogUpstreamHostSelectedGetter string = "UpstreamHostSelected"
)
const (
// ReqHeaderPrefix is the prefix of request header's formatter
ReqHeaderPrefix string = "REQ."
// RespHeaderPrefix is the prefix of response header's formatter
RespHeaderPrefix string = "RESP."
)
const (
// DefaultAccessLogFormat is the default access log format.
// For more details please read "AccessLogDetails.md"
DefaultAccessLogFormat = "%StartTime% %RequestReceivedDuration% %ResponseReceivedDuration% %RequestFinishedDuration% %BytesSent%" + " " +
"%BytesReceived% %Protocol% %ResponseCode% %Duration% %ResponseFlag% %ResponseCode% %UpstreamLocalAddress%" + " " +
"%DownstreamLocalAddress% %DownstreamRemoteAddress% %UpstreamHostSelected%"
)