0
mirror of https://github.com/XTLS/Xray-core.git synced 2025-06-12 11:29:36 +03:00

Refactor log (#3446)

* Refactor log

* Add new log methods

* Fix logger test

* Change all logging code

* Clean up pathObj

* Rebase to latest main

* Remove invoking method name after the dot
This commit is contained in:
yuhan6665
2024-06-29 14:32:57 -04:00
committed by GitHub
parent 8320732743
commit 079d0bd8a9
291 changed files with 1837 additions and 2368 deletions

View File

@ -4,6 +4,7 @@ import (
"io"
"github.com/xtls/xray-core/common/bytespool"
"github.com/xtls/xray-core/common/errors"
"github.com/xtls/xray-core/common/net"
)
@ -226,7 +227,7 @@ func (b *Buffer) Write(data []byte) (int, error) {
// WriteByte writes a single byte into the buffer.
func (b *Buffer) WriteByte(v byte) error {
if b.IsFull() {
return newError("buffer full")
return errors.New("buffer full")
}
b.v[b.end] = v
b.end++
@ -286,7 +287,7 @@ func (b *Buffer) ReadFullFrom(reader io.Reader, size int32) (int64, error) {
end := b.end + size
if end > int32(len(b.v)) {
v := end
return 0, newError("out of bound: ", v)
return 0, errors.New("out of bound: ", v)
}
n, err := io.ReadFull(reader, b.v[b.end:end])
b.end += int32(n)

View File

@ -120,7 +120,7 @@ func Copy(reader Reader, writer Writer, options ...CopyOption) error {
return nil
}
var ErrNotTimeoutReader = newError("not a TimeoutReader")
var ErrNotTimeoutReader = errors.New("not a TimeoutReader")
func CopyOnceTimeout(reader Reader, writer Writer, timeout time.Duration) error {
timeoutReader, ok := reader.(TimeoutReader)

View File

@ -27,7 +27,7 @@ func TestReadError(t *testing.T) {
t.Error("expected to be ReadError, but not")
}
if err.Error() != "error" {
if err.Error() != "common/buf_test: error" {
t.Fatal("unexpected error message: ", err.Error())
}
}
@ -48,7 +48,7 @@ func TestWriteError(t *testing.T) {
t.Error("expected to be WriteError, but not")
}
if err.Error() != "error" {
if err.Error() != "common/buf_test: error" {
t.Fatal("unexpected error message: ", err.Error())
}
}

View File

@ -1,9 +0,0 @@
package buf
import "github.com/xtls/xray-core/common/errors"
type errPathObjHolder struct{}
func newError(values ...interface{}) *errors.Error {
return errors.New(values...).WithPathObj(errPathObjHolder{})
}

View File

@ -1,12 +1,14 @@
package buf
import (
"context"
"io"
"net"
"os"
"syscall"
"time"
"github.com/xtls/xray-core/common/errors"
"github.com/xtls/xray-core/features/stats"
"github.com/xtls/xray-core/transport/internet/stat"
)
@ -18,7 +20,7 @@ type Reader interface {
}
// ErrReadTimeout is an error that happens with IO timeout.
var ErrReadTimeout = newError("IO timeout")
var ErrReadTimeout = errors.New("IO timeout")
// TimeoutReader is a reader that returns error if Read() operation takes longer than the given timeout.
type TimeoutReader interface {
@ -74,7 +76,7 @@ func NewReader(reader io.Reader) Reader {
if sc, ok := reader.(syscall.Conn); ok {
rawConn, err := sc.SyscallConn()
if err != nil {
newError("failed to get sysconn").Base(err).WriteToLog()
errors.LogInfoInner(context.Background(), err, "failed to get sysconn")
} else {
var counter stats.Counter

View File

@ -21,7 +21,7 @@ func readOneUDP(r io.Reader) (*Buffer, error) {
}
b.Release()
return nil, newError("Reader returns too many empty payloads.")
return nil, errors.New("Reader returns too many empty payloads.")
}
// ReadBuffer reads a Buffer from the given reader.