-
Notifications
You must be signed in to change notification settings - Fork 4
/
log.go
54 lines (47 loc) · 1.68 KB
/
log.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
package ginhttplogger
import (
"net/http"
"time"
"github.com/gin-gonic/gin"
)
// Log structure passed through the log forwarding channel
type Log struct {
context *gin.Context
startDate time.Time
latency time.Duration
requestBody string
responseHeaders http.Header
responseBody string
responseContentLength int64
}
// HTTPContent describes the format of a Request body and it's metadata
type HTTPContent struct {
Size int64 `json:"size"`
MimeType string `json:"mime_type,omitempty"`
Content string `json:"value,omitempty"`
}
// RequestLogEntry describes the incoming requests log format
type RequestLogEntry struct {
Method string `json:"method"`
Path string `json:"path"`
HTTPVersion string `json:"http_version"`
Headers map[string]string `json:"headers"`
HeaderSize int `json:"headers_size"`
Content HTTPContent `json:"content"`
}
// ResponseLogEntry describes the server response log format
type ResponseLogEntry struct {
Status int `json:"status,omitempty"`
Headers map[string]string `json:"headers,omitempty"`
HeaderSize int `json:"headers_size"`
Content HTTPContent `json:"content"`
}
// AccessLog describes the complete log entry format
type AccessLog struct {
TimeStarted string `json:"start_time"`
ClientAddress string `json:"x_client_address,omitempty"`
Time int64 `json:"duration"`
Request RequestLogEntry `json:"request"`
Response ResponseLogEntry `json:"response"`
Errors string `json:"errors,omitempty"`
}