feat: 改用 logrus 输出日志
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user