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
|
@ -74,14 +74,14 @@ func parseIPQuery(b []byte) (r bool, domain string, id uint16, qType dnsmessage.
|
|||
var parser dnsmessage.Parser
|
||||
header, err := parser.Start(b)
|
||||
if err != nil {
|
||||
newError("parser start").Base(err).WriteToLog()
|
||||
errors.LogInfoInner(context.Background(), err, "parser start")
|
||||
return
|
||||
}
|
||||
|
||||
id = header.ID
|
||||
q, err := parser.Question()
|
||||
if err != nil {
|
||||
newError("question").Base(err).WriteToLog()
|
||||
errors.LogInfoInner(context.Background(), err, "question")
|
||||
return
|
||||
}
|
||||
qType = q.Type
|
||||
|
@ -97,9 +97,9 @@ func parseIPQuery(b []byte) (r bool, domain string, id uint16, qType dnsmessage.
|
|||
// Process implements proxy.Outbound.
|
||||
func (h *Handler) Process(ctx context.Context, link *transport.Link, d internet.Dialer) error {
|
||||
outbounds := session.OutboundsFromContext(ctx)
|
||||
ob := outbounds[len(outbounds) - 1]
|
||||
ob := outbounds[len(outbounds)-1]
|
||||
if !ob.Target.IsValid() {
|
||||
return newError("invalid outbound")
|
||||
return errors.New("invalid outbound")
|
||||
}
|
||||
ob.Name = "dns"
|
||||
|
||||
|
@ -116,7 +116,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, d internet.
|
|||
dest.Port = h.server.Port
|
||||
}
|
||||
|
||||
newError("handling DNS traffic to ", dest).WriteToLog(session.ExportIDToError(ctx))
|
||||
errors.LogInfo(ctx, "handling DNS traffic to ", dest)
|
||||
|
||||
conn := &outboundConn{
|
||||
dialer: func() (stat.Connection, error) {
|
||||
|
@ -216,7 +216,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, d internet.
|
|||
}
|
||||
|
||||
if err := task.Run(ctx, request, response); err != nil {
|
||||
return newError("connection ends").Base(err)
|
||||
return errors.New("connection ends").Base(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -245,7 +245,7 @@ func (h *Handler) handleIPQuery(id uint16, qType dnsmessage.Type, domain string,
|
|||
|
||||
rcode := dns.RCodeFromError(err)
|
||||
if rcode == 0 && len(ips) == 0 && !errors.AllEqual(dns.ErrEmptyResponse, errors.Cause(err)) {
|
||||
newError("ip query").Base(err).WriteToLog()
|
||||
errors.LogInfoInner(context.Background(), err, "ip query")
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -297,14 +297,14 @@ func (h *Handler) handleIPQuery(id uint16, qType dnsmessage.Type, domain string,
|
|||
}
|
||||
msgBytes, err := builder.Finish()
|
||||
if err != nil {
|
||||
newError("pack message").Base(err).WriteToLog()
|
||||
errors.LogInfoInner(context.Background(), err, "pack message")
|
||||
b.Release()
|
||||
return
|
||||
}
|
||||
b.Resize(0, int32(len(msgBytes)))
|
||||
|
||||
if err := writer.WriteMessage(b); err != nil {
|
||||
newError("write IP answer").Base(err).WriteToLog()
|
||||
errors.LogInfoInner(context.Background(), err, "write IP answer")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -332,7 +332,7 @@ func (c *outboundConn) Write(b []byte) (int, error) {
|
|||
if c.conn == nil {
|
||||
if err := c.dial(); err != nil {
|
||||
c.access.Unlock()
|
||||
newError("failed to dial outbound connection").Base(err).AtWarning().WriteToLog()
|
||||
errors.LogWarningInner(context.Background(), err, "failed to dial outbound connection")
|
||||
return len(b), nil
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
package dns
|
||||
|
||||
import "github.com/xtls/xray-core/common/errors"
|
||||
|
||||
type errPathObjHolder struct{}
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).WithPathObj(errPathObjHolder{})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue