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
|
@ -5,6 +5,7 @@ import (
|
|||
"sync"
|
||||
|
||||
"github.com/xtls/xray-core/common"
|
||||
"github.com/xtls/xray-core/common/errors"
|
||||
)
|
||||
|
||||
// Channel is an implementation of stats.Channel.
|
||||
|
@ -44,7 +45,7 @@ func (c *Channel) Subscribe() (chan interface{}, error) {
|
|||
c.access.Lock()
|
||||
defer c.access.Unlock()
|
||||
if c.subsLimit > 0 && len(c.subscribers) >= c.subsLimit {
|
||||
return nil, newError("Number of subscribers has reached limit")
|
||||
return nil, errors.New("Number of subscribers has reached limit")
|
||||
}
|
||||
subscriber := make(chan interface{}, c.bufferSize)
|
||||
c.subscribers = append(c.subscribers, subscriber)
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
|
||||
"github.com/xtls/xray-core/app/stats"
|
||||
"github.com/xtls/xray-core/common"
|
||||
"github.com/xtls/xray-core/common/errors"
|
||||
"github.com/xtls/xray-core/common/strmatcher"
|
||||
"github.com/xtls/xray-core/core"
|
||||
feature_stats "github.com/xtls/xray-core/features/stats"
|
||||
|
@ -31,7 +32,7 @@ func NewStatsServer(manager feature_stats.Manager) StatsServiceServer {
|
|||
func (s *statsServer) GetStats(ctx context.Context, request *GetStatsRequest) (*GetStatsResponse, error) {
|
||||
c := s.stats.GetCounter(request.Name)
|
||||
if c == nil {
|
||||
return nil, newError(request.Name, " not found.")
|
||||
return nil, errors.New(request.Name, " not found.")
|
||||
}
|
||||
var value int64
|
||||
if request.Reset_ {
|
||||
|
@ -57,7 +58,7 @@ func (s *statsServer) QueryStats(ctx context.Context, request *QueryStatsRequest
|
|||
|
||||
manager, ok := s.stats.(*stats.Manager)
|
||||
if !ok {
|
||||
return nil, newError("QueryStats only works its own stats.Manager.")
|
||||
return nil, errors.New("QueryStats only works its own stats.Manager.")
|
||||
}
|
||||
|
||||
manager.VisitCounters(func(name string, c feature_stats.Counter) bool {
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
package command
|
||||
|
||||
import "github.com/xtls/xray-core/common/errors"
|
||||
|
||||
type errPathObjHolder struct{}
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).WithPathObj(errPathObjHolder{})
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
package stats
|
||||
|
||||
import "github.com/xtls/xray-core/common/errors"
|
||||
|
||||
type errPathObjHolder struct{}
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).WithPathObj(errPathObjHolder{})
|
||||
}
|
|
@ -40,9 +40,9 @@ func (m *Manager) RegisterCounter(name string) (stats.Counter, error) {
|
|||
defer m.access.Unlock()
|
||||
|
||||
if _, found := m.counters[name]; found {
|
||||
return nil, newError("Counter ", name, " already registered.")
|
||||
return nil, errors.New("Counter ", name, " already registered.")
|
||||
}
|
||||
newError("create new counter ", name).AtDebug().WriteToLog()
|
||||
errors.LogDebug(context.Background(), "create new counter ", name)
|
||||
c := new(Counter)
|
||||
m.counters[name] = c
|
||||
return c, nil
|
||||
|
@ -54,7 +54,7 @@ func (m *Manager) UnregisterCounter(name string) error {
|
|||
defer m.access.Unlock()
|
||||
|
||||
if _, found := m.counters[name]; found {
|
||||
newError("remove counter ", name).AtDebug().WriteToLog()
|
||||
errors.LogDebug(context.Background(), "remove counter ", name)
|
||||
delete(m.counters, name)
|
||||
}
|
||||
return nil
|
||||
|
@ -89,9 +89,9 @@ func (m *Manager) RegisterChannel(name string) (stats.Channel, error) {
|
|||
defer m.access.Unlock()
|
||||
|
||||
if _, found := m.channels[name]; found {
|
||||
return nil, newError("Channel ", name, " already registered.")
|
||||
return nil, errors.New("Channel ", name, " already registered.")
|
||||
}
|
||||
newError("create new channel ", name).AtDebug().WriteToLog()
|
||||
errors.LogDebug(context.Background(), "create new channel ", name)
|
||||
c := NewChannel(&ChannelConfig{BufferSize: 64, Blocking: false})
|
||||
m.channels[name] = c
|
||||
if m.running {
|
||||
|
@ -106,7 +106,7 @@ func (m *Manager) UnregisterChannel(name string) error {
|
|||
defer m.access.Unlock()
|
||||
|
||||
if c, found := m.channels[name]; found {
|
||||
newError("remove channel ", name).AtDebug().WriteToLog()
|
||||
errors.LogDebug(context.Background(), "remove channel ", name)
|
||||
delete(m.channels, name)
|
||||
return c.Close()
|
||||
}
|
||||
|
@ -148,7 +148,7 @@ func (m *Manager) Close() error {
|
|||
m.running = false
|
||||
errs := []error{}
|
||||
for name, channel := range m.channels {
|
||||
newError("remove channel ", name).AtDebug().WriteToLog()
|
||||
errors.LogDebug(context.Background(), "remove channel ", name)
|
||||
delete(m.channels, name)
|
||||
if err := channel.Close(); err != nil {
|
||||
errs = append(errs, err)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue