Skip to content

Commit

Permalink
Replace standard log package with logrus
Browse files Browse the repository at this point in the history
The standard "log" package was replaced by the structured logger "github.com/sirupsen/logrus" for better log control in various files. This change will allow to tailor the logging information more precisely and make logs easier to read and analyze. All calls of standard log methods were replaced by their logrus counterparts.
  • Loading branch information
Septrum101 committed Dec 28, 2023
1 parent 5ba0624 commit 115d7ba
Show file tree
Hide file tree
Showing 16 changed files with 99 additions and 82 deletions.
9 changes: 5 additions & 4 deletions api/bunpanel/bunpanel.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"errors"
"fmt"
"log"
"os"
"reflect"
"regexp"
Expand All @@ -14,6 +13,8 @@ import (
"sync"
"time"

log "github.com/sirupsen/logrus"

"github.com/go-resty/resty/v2"

"github.com/XrayR-project/XrayR/api"
Expand Down Expand Up @@ -294,7 +295,7 @@ func (c *APIClient) ParseUserListResponse(userInfoResponse *[]User) (*[]api.User
c.access.Unlock()
}()

var deviceLimit, localDeviceLimit int = 0, 0
var deviceLimit, localDeviceLimit = 0, 0
var speedLimit uint64 = 0
var userList []api.UserInfo
for _, user := range *userInfoResponse {
Expand Down Expand Up @@ -332,8 +333,8 @@ func (c *APIClient) ParseUserListResponse(userInfoResponse *[]User) (*[]api.User
UUID: user.UUID,
SpeedLimit: speedLimit,
DeviceLimit: deviceLimit,
Passwd: user.UUID,
Email: user.UUID + "@bunpanel.user",
Passwd: user.UUID,
Email: user.UUID + "@bunpanel.user",
})
}

Expand Down
3 changes: 2 additions & 1 deletion api/gov2panel/gov2panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import (
"encoding/json"
"errors"
"fmt"
"log"
"os"
"regexp"
"strconv"
"strings"
"sync/atomic"
"time"

log "github.com/sirupsen/logrus"

"github.com/bitly/go-simplejson"
"github.com/go-resty/resty/v2"
"github.com/gogf/gf/v2/util/gconv"
Expand Down
23 changes: 12 additions & 11 deletions api/newV2board/v2board.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import (
"encoding/json"
"errors"
"fmt"
"log"
"os"
"regexp"
"strconv"
"strings"
"sync/atomic"
"time"

log "github.com/sirupsen/logrus"

"github.com/bitly/go-simplejson"
"github.com/go-resty/resty/v2"
"github.com/xtls/xray-core/common/net"
Expand Down Expand Up @@ -57,7 +58,7 @@ func New(apiConfig *api.Config) *APIClient {

var nodeType string

if apiConfig.NodeType =="V2ray" && apiConfig.EnableVless {
if apiConfig.NodeType == "V2ray" && apiConfig.EnableVless {
nodeType = "vless"
} else {
nodeType = strings.ToLower(apiConfig.NodeType)
Expand Down Expand Up @@ -363,12 +364,12 @@ func (c *APIClient) parseSSNodeResponse(s *serverConfig) (*api.NodeInfo, error)
// parseV2rayNodeResponse parse the response for the given nodeInfo format
func (c *APIClient) parseV2rayNodeResponse(s *serverConfig) (*api.NodeInfo, error) {
var (
host string
header json.RawMessage
enableTLS bool
host string
header json.RawMessage
enableTLS bool
enableREALITY bool
dest string
xVer uint64
dest string
xVer uint64
)

if s.VlessTlsSettings.Dest != "" {
Expand All @@ -383,11 +384,11 @@ func (c *APIClient) parseV2rayNodeResponse(s *serverConfig) (*api.NodeInfo, erro
}

realityConfig := api.REALITYConfig{
Dest: dest + ":" + s.VlessTlsSettings.ServerPort,
Dest: dest + ":" + s.VlessTlsSettings.ServerPort,
ProxyProtocolVer: xVer,
ServerNames: []string{s.VlessTlsSettings.Sni},
PrivateKey: s.VlessTlsSettings.PrivateKey,
ShortIds: []string{s.VlessTlsSettings.ShortId},
ServerNames: []string{s.VlessTlsSettings.Sni},
PrivateKey: s.VlessTlsSettings.PrivateKey,
ShortIds: []string{s.VlessTlsSettings.ShortId},
}

if c.EnableVless {
Expand Down
3 changes: 2 additions & 1 deletion api/pmpanel/pmpanel.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import (
"bufio"
"encoding/json"
"fmt"
"log"
"os"
"reflect"
"regexp"
"strconv"
"time"

log "github.com/sirupsen/logrus"

"github.com/go-resty/resty/v2"

"github.com/XrayR-project/XrayR/api"
Expand Down
3 changes: 2 additions & 1 deletion api/proxypanel/proxypanel.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import (
"bufio"
"encoding/json"
"fmt"
"log"
"os"
"reflect"
"regexp"
"strconv"
"time"

log "github.com/sirupsen/logrus"

"github.com/go-resty/resty/v2"

"github.com/XrayR-project/XrayR/api"
Expand Down
5 changes: 3 additions & 2 deletions api/sspanel/sspanel.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"errors"
"fmt"
"log"
"os"
"reflect"
"regexp"
Expand All @@ -14,6 +13,8 @@ import (
"sync"
"time"

log "github.com/sirupsen/logrus"

"github.com/go-resty/resty/v2"

"github.com/XrayR-project/XrayR/api"
Expand Down Expand Up @@ -687,7 +688,7 @@ func (c *APIClient) ParseUserListResponse(userInfoResponse *[]UserResponse) (*[]
c.access.Unlock()
}()

var deviceLimit, localDeviceLimit int = 0, 0
var deviceLimit, localDeviceLimit = 0, 0
var speedLimit uint64 = 0
var userList []api.UserInfo
for _, user := range *userInfoResponse {
Expand Down
13 changes: 7 additions & 6 deletions api/v2raysocks/v2raysocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import (
"encoding/json"
"errors"
"fmt"
"log"
"os"
"regexp"
"strconv"
"strings"
"sync"
"time"

log "github.com/sirupsen/logrus"

"github.com/bitly/go-simplejson"
"github.com/go-resty/resty/v2"
"github.com/sagernet/sing-shadowsocks/shadowaead_2022"
Expand Down Expand Up @@ -57,7 +58,7 @@ func New(apiConfig *api.Config) *APIClient {
log.Print(v.Err)
}
})

// Create Key for each requests
client.SetQueryParams(map[string]string{
"node_id": strconv.Itoa(apiConfig.NodeID),
Expand Down Expand Up @@ -163,7 +164,7 @@ func (c *APIClient) GetNodeInfo() (nodeInfo *api.NodeInfo, err error) {
}).
ForceContentType("application/json").
Get(c.APIHost)

// Etag identifier for a specific version of a resource. StatusCode = 304 means no changed
if res.StatusCode() == 304 {
return nil, errors.New(api.NodeNotModified)
Expand Down Expand Up @@ -217,7 +218,7 @@ func (c *APIClient) GetUserList() (UserList *[]api.UserInfo, err error) {
}).
ForceContentType("application/json").
Get(c.APIHost)

// Etag identifier for a specific version of a resource. StatusCode = 304 means no changed
if res.StatusCode() == 304 {
return nil, errors.New(api.UserNotModified)
Expand Down Expand Up @@ -426,7 +427,7 @@ func (c *APIClient) ParseV2rayNodeResponse(nodeInfoResponse *simplejson.Json) (*
var header json.RawMessage
var enableTLS bool
var enableVless bool
var enableReality bool
var enableReality bool
var alterID uint16 = 0

tmpInboundInfo := nodeInfoResponse.Get("inbounds").MustArray()
Expand Down Expand Up @@ -493,4 +494,4 @@ func (c *APIClient) ParseV2rayNodeResponse(nodeInfoResponse *simplejson.Json) (*
REALITYConfig: realityConfig,
}
return nodeInfo, nil
}
}
3 changes: 2 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"fmt"
"log"
"os"
"os/signal"
"path"
Expand All @@ -11,6 +10,8 @@ import (
"syscall"
"time"

log "github.com/sirupsen/logrus"

"github.com/fsnotify/fsnotify"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand Down
3 changes: 2 additions & 1 deletion common/mylego/accounts_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import (
"encoding/json"
"encoding/pem"
"errors"
"log"
"net/url"
"os"
"path/filepath"
"strings"

log "github.com/sirupsen/logrus"

"github.com/go-acme/lego/v4/certcrypto"
"github.com/go-acme/lego/v4/lego"
"github.com/go-acme/lego/v4/registration"
Expand Down
3 changes: 2 additions & 1 deletion common/mylego/certs_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"bytes"
"crypto/x509"
"encoding/json"
"log"
"os"
"path/filepath"
"strings"

log "github.com/sirupsen/logrus"

"github.com/go-acme/lego/v4/certcrypto"
"github.com/go-acme/lego/v4/certificate"
"golang.org/x/net/idna"
Expand Down
3 changes: 2 additions & 1 deletion common/mylego/renew.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package mylego
import (
"crypto"
"crypto/x509"
"log"
"time"

log "github.com/sirupsen/logrus"

"github.com/go-acme/lego/v4/certcrypto"
"github.com/go-acme/lego/v4/certificate"
"github.com/go-acme/lego/v4/lego"
Expand Down
2 changes: 1 addition & 1 deletion common/mylego/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package mylego

import (
"fmt"
"log"

"github.com/go-acme/lego/v4/certificate"
"github.com/go-acme/lego/v4/lego"
"github.com/go-acme/lego/v4/registration"
log "github.com/sirupsen/logrus"
)

const rootPathWarningMessage = `!!!! HEADS UP !!!!
Expand Down
3 changes: 2 additions & 1 deletion common/mylego/setup.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package mylego

import (
"log"
"os"
"time"

log "github.com/sirupsen/logrus"

"github.com/go-acme/lego/v4/certcrypto"
"github.com/go-acme/lego/v4/challenge/dns01"
"github.com/go-acme/lego/v4/challenge/http01"
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"log"
log "github.com/sirupsen/logrus"

"github.com/XrayR-project/XrayR/cmd"
)
Expand Down
12 changes: 5 additions & 7 deletions panel/panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,27 @@ package panel

import (
"encoding/json"
"log"
"os"
"sync"

"github.com/XrayR-project/XrayR/api/bunpanel"
"github.com/XrayR-project/XrayR/api/gov2panel"
"github.com/XrayR-project/XrayR/api/newV2board"
"github.com/XrayR-project/XrayR/app/mydispatcher"

"dario.cat/mergo"
"github.com/r3labs/diff/v2"
log "github.com/sirupsen/logrus"
"github.com/xtls/xray-core/app/proxyman"
"github.com/xtls/xray-core/app/stats"
"github.com/xtls/xray-core/common/serial"
"github.com/xtls/xray-core/core"
"github.com/xtls/xray-core/infra/conf"

"github.com/XrayR-project/XrayR/api"
"github.com/XrayR-project/XrayR/api/bunpanel"
"github.com/XrayR-project/XrayR/api/gov2panel"
"github.com/XrayR-project/XrayR/api/newV2board"
"github.com/XrayR-project/XrayR/api/pmpanel"
"github.com/XrayR-project/XrayR/api/proxypanel"
"github.com/XrayR-project/XrayR/api/sspanel"
"github.com/XrayR-project/XrayR/api/v2raysocks"
"github.com/XrayR-project/XrayR/app/mydispatcher"
_ "github.com/XrayR-project/XrayR/cmd/distro/all"
"github.com/XrayR-project/XrayR/service"
"github.com/XrayR-project/XrayR/service/controller"
Expand Down Expand Up @@ -155,7 +154,6 @@ func (p *Panel) loadCore(panelConfig *Config) *core.Instance {
if err != nil {
log.Panicf("failed to create instance: %s", err)
}
log.Printf("Xray Core Version: %s", core.Version())

return server
}
Expand Down
Loading

0 comments on commit 115d7ba

Please sign in to comment.