-
Notifications
You must be signed in to change notification settings - Fork 56
/
log.go
52 lines (39 loc) · 1.05 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
package serverHandler
import (
"bytes"
"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) logUpload(filename, fsPath string, r *http.Request) {
if !h.logger.CanLogAccess() {
return
}
buffer := bytes.NewBuffer(make([]byte, 0, LOG_BUF_SIZE))
buffer.WriteString(r.RemoteAddr)
buffer.WriteByte(' ')
buffer.WriteString("save upload file: ")
buffer.WriteString(filename)
buffer.WriteString(" -> ")
buffer.WriteString(fsPath)
h.logger.LogAccess(buffer.Bytes())
}
func (h *handler) logArchive(filename, relPath string, r *http.Request) {
if !h.logger.CanLogAccess() {
return
}
buffer := bytes.NewBuffer(make([]byte, 0, LOG_BUF_SIZE))
buffer.WriteString(r.RemoteAddr)
buffer.WriteByte(' ')
buffer.WriteString("archive file: \"")
buffer.WriteString(filename)
buffer.WriteString("\" <- ")
buffer.WriteString(relPath)
h.logger.LogAccess(buffer.Bytes())
}