-
Notifications
You must be signed in to change notification settings - Fork 0
/
log_entry.go
72 lines (62 loc) · 1.28 KB
/
log_entry.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
package internal
import (
"fmt"
"strings"
"v2ray.com/core/common"
"v2ray.com/core/common/serial"
)
func InterfaceToString(value interface{}) string {
if value == nil {
return " "
}
switch value := value.(type) {
case string:
return value
case *string:
return *value
case fmt.Stringer:
return value.String()
case error:
return value.Error()
case []byte:
return serial.BytesToHexString(value)
default:
return fmt.Sprint(value)
}
}
type LogEntry interface {
common.Releasable
fmt.Stringer
}
type ErrorLog struct {
Prefix string
Values []interface{}
}
func (this *ErrorLog) Release() {
for index := range this.Values {
this.Values[index] = nil
}
this.Values = nil
}
func (this *ErrorLog) String() string {
values := make([]string, len(this.Values)+1)
values[0] = this.Prefix
for i, value := range this.Values {
values[i+1] = InterfaceToString(value)
}
return strings.Join(values, "")
}
type AccessLog struct {
From interface{}
To interface{}
Status string
Reason interface{}
}
func (this *AccessLog) Release() {
this.From = nil
this.To = nil
this.Reason = nil
}
func (this *AccessLog) String() string {
return strings.Join([]string{InterfaceToString(this.From), this.Status, InterfaceToString(this.To), InterfaceToString(this.Reason)}, " ")
}