feat: 优化日志组件,添加日志分级

This commit is contained in:
Mmx233
2022-03-02 22:45:38 +08:00
parent bf757a2bcc
commit f778319a00
6 changed files with 62 additions and 66 deletions

View File

@@ -18,7 +18,7 @@ func Guardian(output bool) {
go Daemon.DaemonChan()
if e := Daemon.MarkDaemon(); e != nil {
util.Log.Fatalln(e)
util.Log.Warn("写入daemon标记文件失败: ", e)
}
}
@@ -31,14 +31,14 @@ func Guardian(output bool) {
}()
if global.Config.Settings.Basic.Interfaces == "" { //单网卡
if !util.Checker.NetOk(global.Transports(nil)) {
util.Log.Println("Network down, trying to login")
util.Log.Info("检测到掉线, trying to login")
e := Login(output, true, nil)
if e != nil {
util.Log.Println("Error: ", e)
util.Log.Warn("登陆失败: ", e)
}
} else {
if global.Config.Settings.Debug.Enable {
util.Log.Println("Network ok")
util.Log.Debug("Network ok")
}
}
} else { //多网卡
@@ -47,16 +47,16 @@ func Guardian(output bool) {
var down []srunModels.Eth
for _, eth := range interfaces {
if !util.Checker.NetOk(global.Transports(eth.Addr)) {
util.Log.Println(eth.Name + " network down")
util.Log.Info("检测到掉线网口 ", eth.Name)
down = append(down, eth)
}
}
for _, eth := range down {
util.Log.Println(eth.Name)
util.Log.Info(eth.Name)
e := Login(output, true, eth.Addr)
if e != nil {
util.Log.Println(eth.Name+" login error: ", e)
util.Log.Warn("网口 ", eth.Name+" 登录失败: ", e)
}
}
}
@@ -71,12 +71,12 @@ func Guardian(output bool) {
// EnterGuardian 守护模式入口控制是否进入daemon
func EnterGuardian() {
util.Log.Println("[Guardian mode]")
util.Log.Info("[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.Fatalln(err)
util.Log.Fatal("启动守护失败: ", err)
}
util.Log.Println("[Daemon mode entered]")
util.Log.Info("[Daemon mode entered]")
return
}
Guardian(true)