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
|
@ -2,6 +2,7 @@ package domainsocket
|
|||
|
||||
import (
|
||||
"github.com/xtls/xray-core/common"
|
||||
"github.com/xtls/xray-core/common/errors"
|
||||
"github.com/xtls/xray-core/common/net"
|
||||
"github.com/xtls/xray-core/transport/internet"
|
||||
)
|
||||
|
@ -14,7 +15,7 @@ const (
|
|||
func (c *Config) GetUnixAddr() (*net.UnixAddr, error) {
|
||||
path := c.Path
|
||||
if path == "" {
|
||||
return nil, newError("empty domain socket path")
|
||||
return nil, errors.New("empty domain socket path")
|
||||
}
|
||||
if c.Abstract && path[0] != '@' {
|
||||
path = "@" + path
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"context"
|
||||
|
||||
"github.com/xtls/xray-core/common"
|
||||
"github.com/xtls/xray-core/common/errors"
|
||||
"github.com/xtls/xray-core/common/net"
|
||||
"github.com/xtls/xray-core/transport/internet"
|
||||
"github.com/xtls/xray-core/transport/internet/reality"
|
||||
|
@ -23,7 +24,7 @@ func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.Me
|
|||
|
||||
conn, err := net.DialUnix("unix", nil, addr)
|
||||
if err != nil {
|
||||
return nil, newError("failed to dial unix: ", settings.Path).Base(err).AtWarning()
|
||||
return nil, errors.New("failed to dial unix: ", settings.Path).Base(err).AtWarning()
|
||||
}
|
||||
|
||||
if config := tls.ConfigFromStreamSettings(streamSettings); config != nil {
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
package domainsocket
|
||||
|
||||
import "github.com/xtls/xray-core/common/errors"
|
||||
|
||||
type errPathObjHolder struct{}
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).WithPathObj(errPathObjHolder{})
|
||||
}
|
|
@ -11,6 +11,7 @@ import (
|
|||
|
||||
goreality "github.com/xtls/reality"
|
||||
"github.com/xtls/xray-core/common"
|
||||
"github.com/xtls/xray-core/common/errors"
|
||||
"github.com/xtls/xray-core/common/net"
|
||||
"github.com/xtls/xray-core/transport/internet"
|
||||
"github.com/xtls/xray-core/transport/internet/reality"
|
||||
|
@ -38,7 +39,7 @@ func Listen(ctx context.Context, address net.Address, port net.Port, streamSetti
|
|||
|
||||
unixListener, err := net.ListenUnix("unix", addr)
|
||||
if err != nil {
|
||||
return nil, newError("failed to listen domain socket").Base(err).AtWarning()
|
||||
return nil, errors.New("failed to listen domain socket").Base(err).AtWarning()
|
||||
}
|
||||
|
||||
ln := &Listener{
|
||||
|
@ -88,7 +89,7 @@ func (ln *Listener) run() {
|
|||
if strings.Contains(err.Error(), "closed") {
|
||||
break
|
||||
}
|
||||
newError("failed to accepted raw connections").Base(err).AtWarning().WriteToLog()
|
||||
errors.LogWarningInner(context.Background(), err, "failed to accepted raw connections")
|
||||
continue
|
||||
}
|
||||
go func() {
|
||||
|
@ -96,7 +97,7 @@ func (ln *Listener) run() {
|
|||
conn = tls.Server(conn, ln.tlsConfig)
|
||||
} else if ln.realityConfig != nil {
|
||||
if conn, err = reality.Server(conn, ln.realityConfig); err != nil {
|
||||
newError(err).AtInfo().WriteToLog()
|
||||
errors.LogInfo(context.Background(), err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -117,7 +118,7 @@ func (fl *fileLocker) Acquire() error {
|
|||
}
|
||||
if err := unix.Flock(int(f.Fd()), unix.LOCK_EX); err != nil {
|
||||
f.Close()
|
||||
return newError("failed to lock file: ", fl.path).Base(err)
|
||||
return errors.New("failed to lock file: ", fl.path).Base(err)
|
||||
}
|
||||
fl.file = f
|
||||
return nil
|
||||
|
@ -125,13 +126,13 @@ func (fl *fileLocker) Acquire() error {
|
|||
|
||||
func (fl *fileLocker) Release() {
|
||||
if err := unix.Flock(int(fl.file.Fd()), unix.LOCK_UN); err != nil {
|
||||
newError("failed to unlock file: ", fl.path).Base(err).WriteToLog()
|
||||
errors.LogInfoInner(context.Background(), err, "failed to unlock file: ", fl.path)
|
||||
}
|
||||
if err := fl.file.Close(); err != nil {
|
||||
newError("failed to close file: ", fl.path).Base(err).WriteToLog()
|
||||
errors.LogInfoInner(context.Background(), err, "failed to close file: ", fl.path)
|
||||
}
|
||||
if err := os.Remove(fl.path); err != nil {
|
||||
newError("failed to remove file: ", fl.path).Base(err).WriteToLog()
|
||||
errors.LogInfoInner(context.Background(), err, "failed to remove file: ", fl.path)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue