1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-07 10:47:48 -05:00
v2fly/common/log/internal/log_entry.go

73 lines
1.3 KiB
Go
Raw Normal View History

2016-05-12 02:24:41 -04:00
package internal
import (
"fmt"
2016-07-15 15:15:41 -04:00
"strings"
2016-05-12 02:24:41 -04:00
2016-08-20 14:55:45 -04:00
"v2ray.com/core/common"
"v2ray.com/core/common/serial"
2016-05-12 02:24:41 -04:00
)
2016-05-24 16:41:51 -04:00
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:
2016-11-27 02:47:11 -05:00
return fmt.Sprintf("%+v", value)
2016-05-24 16:41:51 -04:00
}
}
2016-05-12 02:24:41 -04:00
type LogEntry interface {
common.Releasable
2016-05-24 15:55:46 -04:00
fmt.Stringer
2016-05-12 02:24:41 -04:00
}
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 {
2016-07-15 15:15:41 -04:00
values := make([]string, len(this.Values)+1)
values[0] = this.Prefix
for i, value := range this.Values {
values[i+1] = InterfaceToString(value)
2016-05-12 02:24:41 -04:00
}
2016-07-15 15:15:41 -04:00
return strings.Join(values, "")
2016-05-12 02:24:41 -04:00
}
type AccessLog struct {
2016-05-24 16:41:51 -04:00
From interface{}
To interface{}
2016-05-12 02:24:41 -04:00
Status string
2016-05-24 16:41:51 -04:00
Reason interface{}
2016-05-12 02:24:41 -04:00
}
func (this *AccessLog) Release() {
this.From = nil
this.To = nil
this.Reason = nil
}
func (this *AccessLog) String() string {
2016-07-15 15:15:41 -04:00
return strings.Join([]string{InterfaceToString(this.From), this.Status, InterfaceToString(this.To), InterfaceToString(this.Reason)}, " ")
2016-05-12 02:24:41 -04:00
}