feat: 改用 logrus 输出日志

This commit is contained in:
Mmx233
2022-08-14 20:47:23 +08:00
parent 51e06a1596
commit df87d75aca
14 changed files with 107 additions and 181 deletions

View File

@@ -3,44 +3,43 @@ package controllers
import (
"github.com/Mmx233/BitSrunLoginGo/global"
"github.com/Mmx233/BitSrunLoginGo/util"
log "github.com/sirupsen/logrus"
"os"
"os/exec"
"time"
)
// Guardian 守护模式逻辑
func Guardian(output bool) {
util.Log.OutPut = output
func Guardian() {
GuardianDuration := time.Duration(global.Config.Settings.Guardian.Duration) * time.Second
if global.Config.Settings.Daemon.Enable {
go Daemon.DaemonChan()
if e := Daemon.MarkDaemon(); e != nil {
util.Log.Warn("写入daemon标记文件失败: ", e)
log.Warnln("写入daemon标记文件失败: ", e)
}
}
var c = make(chan bool)
for {
util.Log.OutPut = output
go func() {
defer func() {
_ = recover()
}()
if global.Config.Settings.Basic.Interfaces == "" { //单网卡
e := Login(output, nil)
e := Login(nil)
if e != nil {
util.Log.Warn("登陆失败: ", e)
log.Errorln("登陆失败: ", e)
}
} else { //多网卡
interfaces, e := util.GetInterfaceAddr()
if e == nil {
for _, eth := range interfaces {
util.Log.Info(eth.Name)
e := Login(output, eth.Addr)
log.Infoln(eth.Name)
e = Login(eth.Addr)
if e != nil {
util.Log.Warn("网口 ", eth.Name+" 登录失败: ", e)
log.Errorln("网口 ", eth.Name+" 登录失败: ", e)
}
}
}
@@ -55,13 +54,13 @@ func Guardian(output bool) {
// EnterGuardian 守护模式入口控制是否进入daemon
func EnterGuardian() {
util.Log.Info("[Guardian mode]")
log.Infoln("[Guardian mode]")
if global.Config.Settings.Daemon.Enable || global.Flags.Daemon {
if err := exec.Command(os.Args[0], append(os.Args[1:], "--running-daemon")...).Start(); err != nil {
util.Log.Fatal("启动守护失败: ", err)
log.Fatalln("启动守护失败: ", err)
}
util.Log.Info("[Daemon mode entered]")
log.Infoln("[Daemon mode entered]")
return
}
Guardian(true)
Guardian()
}

View File

@@ -9,12 +9,9 @@ import (
)
// Login 登录逻辑
func Login(output bool, localAddr net.Addr) error {
func Login(localAddr net.Addr) error {
return BitSrun.Login(&srunTransfer.Login{
Https: global.Config.Settings.Basic.Https,
Debug: global.Config.Settings.Debug.Enable,
WriteLog: global.Config.Settings.Debug.WriteLog,
OutPut: output,
Https: global.Config.Settings.Basic.Https,
LoginInfo: srunTransfer.LoginInfo{
Form: &global.Config.Form,
Meta: &global.Config.Meta,