log_entry.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package internal
  2. import (
  3. "fmt"
  4. "github.com/v2ray/v2ray-core/common"
  5. "github.com/v2ray/v2ray-core/common/alloc"
  6. "github.com/v2ray/v2ray-core/common/serial"
  7. )
  8. type LogEntry interface {
  9. common.Releasable
  10. serial.String
  11. }
  12. type ErrorLog struct {
  13. Prefix string
  14. Values []interface{}
  15. }
  16. func (this *ErrorLog) Release() {
  17. for index := range this.Values {
  18. this.Values[index] = nil
  19. }
  20. this.Values = nil
  21. }
  22. func (this *ErrorLog) String() string {
  23. b := alloc.NewSmallBuffer().Clear()
  24. defer b.Release()
  25. b.AppendString(this.Prefix)
  26. for _, value := range this.Values {
  27. switch typedVal := value.(type) {
  28. case string:
  29. b.AppendString(typedVal)
  30. case *string:
  31. b.AppendString(*typedVal)
  32. case serial.String:
  33. b.AppendString(typedVal.String())
  34. case error:
  35. b.AppendString(typedVal.Error())
  36. default:
  37. b.AppendString(fmt.Sprint(value))
  38. }
  39. }
  40. return b.String()
  41. }
  42. type AccessLog struct {
  43. From serial.String
  44. To serial.String
  45. Status string
  46. Reason serial.String
  47. }
  48. func (this *AccessLog) Release() {
  49. this.From = nil
  50. this.To = nil
  51. this.Reason = nil
  52. }
  53. func (this *AccessLog) String() string {
  54. b := alloc.NewSmallBuffer().Clear()
  55. defer b.Release()
  56. return b.AppendString(this.From.String()).AppendString(" ").AppendString(this.Status).AppendString(" ").AppendString(this.To.String()).AppendString(" ").AppendString(this.Reason.String()).String()
  57. }