mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-04-30 09:18:34 +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
|
@ -1,9 +0,0 @@
|
|||
package freedom
|
||||
|
||||
import "github.com/xtls/xray-core/common/errors"
|
||||
|
||||
type errPathObjHolder struct{}
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).WithPathObj(errPathObjHolder{})
|
||||
}
|
|
@ -13,6 +13,7 @@ import (
|
|||
"github.com/xtls/xray-core/common"
|
||||
"github.com/xtls/xray-core/common/buf"
|
||||
"github.com/xtls/xray-core/common/dice"
|
||||
"github.com/xtls/xray-core/common/errors"
|
||||
"github.com/xtls/xray-core/common/net"
|
||||
"github.com/xtls/xray-core/common/platform"
|
||||
"github.com/xtls/xray-core/common/retry"
|
||||
|
@ -87,7 +88,7 @@ func (h *Handler) resolveIP(ctx context.Context, domain string, localAddr net.Ad
|
|||
}
|
||||
}
|
||||
if err != nil {
|
||||
newError("failed to get IP address for domain ", domain).Base(err).WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogInfoInner(ctx, err, "failed to get IP address for domain ", domain)
|
||||
}
|
||||
if len(ips) == 0 {
|
||||
return nil
|
||||
|
@ -107,9 +108,9 @@ func isValidAddress(addr *net.IPOrDomain) bool {
|
|||
// Process implements proxy.Outbound.
|
||||
func (h *Handler) 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 = "freedom"
|
||||
ob.CanSpliceCopy = 1
|
||||
|
@ -143,7 +144,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
|
|||
Address: ip,
|
||||
Port: dialDest.Port,
|
||||
}
|
||||
newError("dialing to ", dialDest).WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogInfo(ctx, "dialing to ", dialDest)
|
||||
} else if h.config.forceIP() {
|
||||
return dns.ErrEmptyResponse
|
||||
}
|
||||
|
@ -169,10 +170,10 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
|
|||
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()
|
||||
newError("connection opened to ", destination, ", local endpoint ", conn.LocalAddr(), ", remote endpoint ", conn.RemoteAddr()).WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogInfo(ctx, "connection opened to ", destination, ", local endpoint ", conn.LocalAddr(), ", remote endpoint ", conn.RemoteAddr())
|
||||
|
||||
var newCtx context.Context
|
||||
var newCancel context.CancelFunc
|
||||
|
@ -195,8 +196,8 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
|
|||
var writer buf.Writer
|
||||
if destination.Network == net.Network_TCP {
|
||||
if h.config.Fragment != nil {
|
||||
newError("FRAGMENT", h.config.Fragment.PacketsFrom, h.config.Fragment.PacketsTo, h.config.Fragment.LengthMin, h.config.Fragment.LengthMax,
|
||||
h.config.Fragment.IntervalMin, h.config.Fragment.IntervalMax).AtDebug().WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogDebug(ctx, "FRAGMENT", h.config.Fragment.PacketsFrom, h.config.Fragment.PacketsTo, h.config.Fragment.LengthMin, h.config.Fragment.LengthMax,
|
||||
h.config.Fragment.IntervalMin, h.config.Fragment.IntervalMax)
|
||||
writer = buf.NewWriter(&FragmentWriter{
|
||||
fragment: h.config.Fragment,
|
||||
writer: conn,
|
||||
|
@ -209,7 +210,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
|
|||
}
|
||||
|
||||
if err := buf.Copy(input, writer, buf.UpdateActivity(timer)); err != nil {
|
||||
return newError("failed to process request").Base(err)
|
||||
return errors.New("failed to process request").Base(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -228,7 +229,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
|
|||
}
|
||||
reader := NewPacketReader(conn, UDPOverride)
|
||||
if err := buf.Copy(reader, output, buf.UpdateActivity(timer)); err != nil {
|
||||
return newError("failed to process response").Base(err)
|
||||
return errors.New("failed to process response").Base(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -238,7 +239,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte
|
|||
}
|
||||
|
||||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue