-
Notifications
You must be signed in to change notification settings - Fork 56
/
log.go
75 lines (58 loc) · 1.88 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package serverHandler
import (
"net/http"
)
const LOG_BUF_SIZE = 80
func (h *handler) logRequest(r *http.Request) {
if !h.logger.CanLogAccess() {
return
}
payload := []byte(r.RemoteAddr + " " + r.Method + " " + r.RequestURI)
h.logger.LogAccess(payload)
}
func (h *handler) logMutate(username, action, detail string, r *http.Request) {
if !h.logger.CanLogAccess() {
return
}
buf := make([]byte, 0, LOG_BUF_SIZE)
buf = append(buf, []byte(r.RemoteAddr)...) // 9-47 bytes, mainly 21 bytes
if len(username) > 0 {
buf = append(buf, []byte(" (")...) // 2 bytes
buf = append(buf, []byte(username)...)
buf = append(buf, ')') // 1 byte
}
buf = append(buf, ' ') // 1 byte
buf = append(buf, []byte(action)...) // 5-6 bytes
buf = append(buf, []byte(": ")...) // 2 bytes
buf = append(buf, []byte(detail)...)
h.logger.LogAccess(buf)
}
func (h *handler) logUpload(username, filename, fsPath string, r *http.Request) {
if !h.logger.CanLogAccess() {
return
}
buf := make([]byte, 0, LOG_BUF_SIZE)
buf = append(buf, []byte(r.RemoteAddr)...) // 9-47 bytes, mainly 21 bytes
if len(username) > 0 {
buf = append(buf, []byte(" (")...) // 2 bytes
buf = append(buf, []byte(username)...)
buf = append(buf, ')') // 1 byte
}
buf = append(buf, []byte(" upload: ")...) // 9 bytes
buf = append(buf, []byte(filename)...)
buf = append(buf, []byte(" -> ")...) // 4 bytes
buf = append(buf, []byte(fsPath)...)
h.logger.LogAccess(buf)
}
func (h *handler) logArchive(filename, relPath string, r *http.Request) {
if !h.logger.CanLogAccess() {
return
}
buf := make([]byte, 0, LOG_BUF_SIZE)
buf = append(buf, []byte(r.RemoteAddr)...) // 9-47 bytes, mainly 21 bytes
buf = append(buf, []byte(" archive file: ")...) // 15 bytes
buf = append(buf, []byte(filename)...)
buf = append(buf, []byte(" <- ")...) // 4 bytes
buf = append(buf, []byte(relPath)...)
h.logger.LogAccess(buf)
}