v2ray-core/common/log/internal/log_entry.go

72 lines
1.4 KiB
Go
Raw Normal View History

2016-05-12 06:24:41 +00:00
package internal
import (
"fmt"
"github.com/v2ray/v2ray-core/common"
"github.com/v2ray/v2ray-core/common/alloc"
2016-05-24 20:09:22 +00:00
"github.com/v2ray/v2ray-core/common/serial"
2016-05-12 06:24:41 +00:00
)
type LogEntry interface {
common.Releasable
2016-05-24 19:55:46 +00:00
fmt.Stringer
2016-05-12 06:24:41 +00: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 {
switch typedVal := value.(type) {
case string:
b.AppendString(typedVal)
case *string:
b.AppendString(*typedVal)
2016-05-24 19:55:46 +00:00
case fmt.Stringer:
2016-05-12 06:24:41 +00:00
b.AppendString(typedVal.String())
case error:
b.AppendString(typedVal.Error())
2016-05-24 20:09:22 +00:00
case []byte:
b.AppendString(serial.BytesToHexString(typedVal))
2016-05-12 06:24:41 +00:00
default:
b.AppendString(fmt.Sprint(value))
}
}
return b.String()
}
type AccessLog struct {
2016-05-24 19:55:46 +00:00
From fmt.Stringer
To fmt.Stringer
2016-05-12 06:24:41 +00:00
Status string
2016-05-24 19:55:46 +00:00
Reason fmt.Stringer
2016-05-12 06:24:41 +00: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()
return b.AppendString(this.From.String()).AppendString(" ").AppendString(this.Status).AppendString(" ").AppendString(this.To.String()).AppendString(" ").AppendString(this.Reason.String()).String()
}