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
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
291 changed files with 1837 additions and 2368 deletions

View file

@ -5,6 +5,7 @@ import (
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/buf"
"github.com/xtls/xray-core/common/errors"
"github.com/xtls/xray-core/common/net"
"github.com/xtls/xray-core/common/net/cnc"
"github.com/xtls/xray-core/common/retry"
@ -23,14 +24,14 @@ type Loopback struct {
func (l *Loopback) Process(ctx context.Context, link *transport.Link, _ internet.Dialer) error {
outbounds := session.OutboundsFromContext(ctx)
ob := outbounds[len(outbounds) - 1]
ob := outbounds[len(outbounds)-1]
if !ob.Target.IsValid() {
return newError("target not specified.")
return errors.New("target not specified.")
}
ob.Name = "loopback"
destination := ob.Target
newError("opening connection to ", destination).WriteToLog(session.ExportIDToError(ctx))
errors.LogInfo(ctx, "opening connection to ", destination)
input := link.Reader
output := link.Writer
@ -66,7 +67,7 @@ func (l *Loopback) Process(ctx context.Context, link *transport.Link, _ internet
return nil
})
if err != nil {
return newError("failed to open connection to ", destination).Base(err)
return errors.New("failed to open connection to ", destination).Base(err)
}
defer conn.Close()
@ -79,7 +80,7 @@ func (l *Loopback) Process(ctx context.Context, link *transport.Link, _ internet
}
if err := buf.Copy(input, writer); err != nil {
return newError("failed to process request").Base(err)
return errors.New("failed to process request").Base(err)
}
return nil
@ -93,14 +94,14 @@ func (l *Loopback) Process(ctx context.Context, link *transport.Link, _ internet
reader = buf.NewPacketReader(conn)
}
if err := buf.Copy(reader, output); err != nil {
return newError("failed to process response").Base(err)
return errors.New("failed to process response").Base(err)
}
return nil
}
if err := task.Run(ctx, requestDone, task.OnSuccess(responseDone, task.Close(output))); err != nil {
return newError("connection ends").Base(err)
return errors.New("connection ends").Base(err)
}
return nil