improve: pass logger instead of using global logger

This commit is contained in:
Mmx
2024-09-24 23:36:09 +08:00
parent e1ff68cfc2
commit 78a1b2662d
15 changed files with 163 additions and 126 deletions

View File

@@ -4,7 +4,6 @@ import (
"github.com/Mmx233/BitSrunLoginGo/internal/config"
"github.com/Mmx233/BitSrunLoginGo/internal/controllers"
"github.com/Mmx233/BitSrunLoginGo/tools"
log "github.com/sirupsen/logrus"
)
func main() {
@@ -14,21 +13,22 @@ func main() {
} else {
//登录流程
var err error
logger := config.Logger
if config.Settings.Basic.Interfaces == "" { //单网卡
if err = controllers.Login(nil, false); err != nil {
log.Errorln("登录出错: ", err)
logger.Errorln("登录出错: ", err)
if !config.Settings.Log.DebugLevel {
log.Infoln("开启调试日志debug_level获取详细信息")
logger.Infoln("开启调试日志debug_level获取详细信息")
}
return
}
} else { //多网卡
log.Infoln("多网卡模式")
interfaces, _ := tools.GetInterfaceAddr(config.Settings.Basic.Interfaces)
logger.Infoln("多网卡模式")
interfaces, _ := tools.GetInterfaceAddr(logger, config.Settings.Basic.Interfaces)
for _, eth := range interfaces {
log.Infoln("使用网卡: ", eth.Name)
logger.Infoln("使用网卡: ", eth.Name)
if err = controllers.Login(&eth, false); err != nil {
log.Errorf("网卡 %s 登录出错: %v", eth.Name, err)
config.Logger.Errorf("网卡 %s 登录出错: %v", eth.Name, err)
}
}
}