1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-15 16:38:16 -04:00
v2fly/common/log/internal/log_entry.go

83 lines
1.5 KiB
Go
Raw Normal View History

2016-05-12 02:24:41 -04:00
package internal
import (
"fmt"
"github.com/v2ray/v2ray-core/common"
"github.com/v2ray/v2ray-core/common/alloc"
2016-05-24 16:09:22 -04:00
"github.com/v2ray/v2ray-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:
return fmt.Sprint(value)
}
}
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 {
b := alloc.NewSmallBuffer().Clear()
defer b.Release()
b.AppendString(this.Prefix)
for _, value := range this.Values {
2016-05-24 16:41:51 -04:00
b.AppendString(InterfaceToString(value))
2016-05-12 02:24:41 -04:00
}
return b.String()
}
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 {
b := alloc.NewSmallBuffer().Clear()
defer b.Release()
2016-05-24 16:41:51 -04:00
b.AppendString(InterfaceToString(this.From)).AppendString(" ")
b.AppendString(this.Status).AppendString(" ")
b.AppendString(InterfaceToString(this.To)).AppendString(" ")
b.AppendString(InterfaceToString(this.Reason))
return b.String()
2016-05-12 02:24:41 -04:00
}