mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-04-30 17:38:41 +00: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:
parent
8320732743
commit
079d0bd8a9
291 changed files with 1837 additions and 2368 deletions
|
@ -14,6 +14,7 @@ import (
|
|||
"github.com/xtls/xray-core/common"
|
||||
"github.com/xtls/xray-core/common/buf"
|
||||
"github.com/xtls/xray-core/common/bytespool"
|
||||
"github.com/xtls/xray-core/common/errors"
|
||||
"github.com/xtls/xray-core/common/net"
|
||||
"github.com/xtls/xray-core/common/protocol"
|
||||
"github.com/xtls/xray-core/common/retry"
|
||||
|
@ -51,12 +52,12 @@ func NewClient(ctx context.Context, config *ClientConfig) (*Client, error) {
|
|||
for _, rec := range config.Server {
|
||||
s, err := protocol.NewServerSpecFromPB(rec)
|
||||
if err != nil {
|
||||
return nil, newError("failed to get server spec").Base(err)
|
||||
return nil, errors.New("failed to get server spec").Base(err)
|
||||
}
|
||||
serverList.AddServer(s)
|
||||
}
|
||||
if serverList.Size() == 0 {
|
||||
return nil, newError("0 target server")
|
||||
return nil, errors.New("0 target server")
|
||||
}
|
||||
|
||||
v := core.MustFromContext(ctx)
|
||||
|
@ -70,9 +71,9 @@ func NewClient(ctx context.Context, config *ClientConfig) (*Client, error) {
|
|||
// Process implements proxy.Outbound.Process. We first create a socket tunnel via HTTP CONNECT method, then redirect all inbound traffic to that tunnel.
|
||||
func (c *Client) Process(ctx context.Context, link *transport.Link, dialer 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 = "http"
|
||||
ob.CanSpliceCopy = 2
|
||||
|
@ -80,7 +81,7 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter
|
|||
targetAddr := target.NetAddr()
|
||||
|
||||
if target.Network == net.Network_UDP {
|
||||
return newError("UDP is not supported by HTTP outbound")
|
||||
return errors.New("UDP is not supported by HTTP outbound")
|
||||
}
|
||||
|
||||
var user *protocol.MemoryUser
|
||||
|
@ -97,7 +98,7 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter
|
|||
|
||||
header, err := fillRequestHeader(ctx, c.header)
|
||||
if err != nil {
|
||||
return newError("failed to fill out header").Base(err)
|
||||
return errors.New("failed to fill out header").Base(err)
|
||||
}
|
||||
|
||||
if err := retry.ExponentialBackoff(5, 100).On(func() error {
|
||||
|
@ -117,12 +118,12 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter
|
|||
}
|
||||
return err
|
||||
}); err != nil {
|
||||
return newError("failed to find an available destination").Base(err)
|
||||
return errors.New("failed to find an available destination").Base(err)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if err := conn.Close(); err != nil {
|
||||
newError("failed to closed connection").Base(err).WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogInfoInner(ctx, err, "failed to closed connection")
|
||||
}
|
||||
}()
|
||||
|
||||
|
@ -160,7 +161,7 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter
|
|||
|
||||
responseDonePost := task.OnSuccess(responseFunc, task.Close(link.Writer))
|
||||
if err := task.Run(ctx, requestFunc, responseDonePost); err != nil {
|
||||
return newError("connection ends").Base(err)
|
||||
return errors.New("connection ends").Base(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -174,10 +175,10 @@ func fillRequestHeader(ctx context.Context, header []*Header) ([]*Header, error)
|
|||
|
||||
inbound := session.InboundFromContext(ctx)
|
||||
outbounds := session.OutboundsFromContext(ctx)
|
||||
ob := outbounds[len(outbounds) - 1]
|
||||
ob := outbounds[len(outbounds)-1]
|
||||
|
||||
if inbound == nil || ob == nil {
|
||||
return nil, newError("missing inbound or outbound metadata from context")
|
||||
return nil, errors.New("missing inbound or outbound metadata from context")
|
||||
}
|
||||
|
||||
data := struct {
|
||||
|
@ -242,7 +243,7 @@ func setUpHTTPTunnel(ctx context.Context, dest net.Destination, target string, u
|
|||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
rawConn.Close()
|
||||
return nil, newError("Proxy responded with non 200 code: " + resp.Status)
|
||||
return nil, errors.New("Proxy responded with non 200 code: " + resp.Status)
|
||||
}
|
||||
return rawConn, nil
|
||||
}
|
||||
|
@ -274,7 +275,7 @@ func setUpHTTPTunnel(ctx context.Context, dest net.Destination, target string, u
|
|||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
rawConn.Close()
|
||||
return nil, newError("Proxy responded with non 200 code: " + resp.Status)
|
||||
return nil, errors.New("Proxy responded with non 200 code: " + resp.Status)
|
||||
}
|
||||
return newHTTP2Conn(rawConn, pw, resp.Body), nil
|
||||
}
|
||||
|
@ -344,7 +345,7 @@ func setUpHTTPTunnel(ctx context.Context, dest net.Destination, target string, u
|
|||
|
||||
return proxyConn, err
|
||||
default:
|
||||
return nil, newError("negotiated unsupported application layer protocol: " + nextProto)
|
||||
return nil, errors.New("negotiated unsupported application layer protocol: " + nextProto)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue