mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-04-30 01:08:33 +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
21
core/xray.go
21
core/xray.go
|
@ -6,6 +6,7 @@ import (
|
|||
"sync"
|
||||
|
||||
"github.com/xtls/xray-core/common"
|
||||
"github.com/xtls/xray-core/common/errors"
|
||||
"github.com/xtls/xray-core/common/platform"
|
||||
"github.com/xtls/xray-core/common/serial"
|
||||
"github.com/xtls/xray-core/features"
|
||||
|
@ -104,7 +105,7 @@ func AddInboundHandler(server *Instance, config *InboundHandlerConfig) error {
|
|||
}
|
||||
handler, ok := rawHandler.(inbound.Handler)
|
||||
if !ok {
|
||||
return newError("not an InboundHandler")
|
||||
return errors.New("not an InboundHandler")
|
||||
}
|
||||
if err := inboundManager.AddHandler(server.ctx, handler); err != nil {
|
||||
return err
|
||||
|
@ -130,7 +131,7 @@ func AddOutboundHandler(server *Instance, config *OutboundHandlerConfig) error {
|
|||
}
|
||||
handler, ok := rawHandler.(outbound.Handler)
|
||||
if !ok {
|
||||
return newError("not an OutboundHandler")
|
||||
return errors.New("not an OutboundHandler")
|
||||
}
|
||||
if err := outboundManager.AddHandler(server.ctx, handler); err != nil {
|
||||
return err
|
||||
|
@ -181,7 +182,7 @@ func NewWithContext(ctx context.Context, config *Config) (*Instance, error) {
|
|||
}
|
||||
|
||||
func initInstanceWithConfig(config *Config, server *Instance) (bool, error) {
|
||||
server.ctx = context.WithValue(server.ctx, "cone",
|
||||
server.ctx = context.WithValue(server.ctx, "cone",
|
||||
platform.NewEnvFlag(platform.UseCone).GetValue(func() string { return "" }) != "true")
|
||||
|
||||
if config.Transport != nil {
|
||||
|
@ -234,7 +235,7 @@ func initInstanceWithConfig(config *Config, server *Instance) (bool, error) {
|
|||
)
|
||||
|
||||
if server.featureResolutions != nil {
|
||||
return true, newError("not all dependency are resolved.")
|
||||
return true, errors.New("not all dependency are resolved.")
|
||||
}
|
||||
|
||||
if err := addInboundHandlers(server, config.Inbound); err != nil {
|
||||
|
@ -259,14 +260,14 @@ func (s *Instance) Close() error {
|
|||
|
||||
s.running = false
|
||||
|
||||
var errors []interface{}
|
||||
var errs []interface{}
|
||||
for _, f := range s.features {
|
||||
if err := f.Close(); err != nil {
|
||||
errors = append(errors, err)
|
||||
errs = append(errs, err)
|
||||
}
|
||||
}
|
||||
if len(errors) > 0 {
|
||||
return newError("failed to close all features").Base(newError(serial.Concat(errors...)))
|
||||
if len(errs) > 0 {
|
||||
return errors.New("failed to close all features").Base(errors.New(serial.Concat(errs...)))
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -302,7 +303,7 @@ func (s *Instance) AddFeature(feature features.Feature) error {
|
|||
|
||||
if s.running {
|
||||
if err := feature.Start(); err != nil {
|
||||
newError("failed to start feature").Base(err).WriteToLog()
|
||||
errors.LogInfoInner(s.ctx, err, "failed to start feature")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -350,7 +351,7 @@ func (s *Instance) Start() error {
|
|||
}
|
||||
}
|
||||
|
||||
newError("Xray ", Version(), " started").AtWarning().WriteToLog()
|
||||
errors.LogWarning(s.ctx, "Xray ", Version(), " started")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue