modularize logger (#94)

This commit is contained in:
UUBulb
2024-11-24 16:50:03 +08:00
committed by GitHub
parent 88efe2d1d5
commit b7bba7ed3f
5 changed files with 81 additions and 39 deletions
+3 -5
View File
@@ -11,6 +11,7 @@ import (
"github.com/shirou/gopsutil/v4/process"
"github.com/nezhahq/agent/model"
"github.com/nezhahq/agent/pkg/logger"
"github.com/nezhahq/agent/pkg/monitor/conn"
"github.com/nezhahq/agent/pkg/monitor/cpu"
"github.com/nezhahq/agent/pkg/monitor/disk"
@@ -18,12 +19,13 @@ import (
"github.com/nezhahq/agent/pkg/monitor/load"
"github.com/nezhahq/agent/pkg/monitor/nic"
"github.com/nezhahq/agent/pkg/monitor/temperature"
"github.com/nezhahq/agent/pkg/util"
)
var (
Version string
agentConfig *model.AgentConfig
printf = logger.DefaultLogger.Printf
)
var (
@@ -279,7 +281,3 @@ func tryStat[T any](ctx context.Context, typ uint8, f hostStateFunc[T]) T {
}
return val
}
func printf(format string, v ...interface{}) {
util.Printf(agentConfig.Debug, format, v...)
}
+2 -1
View File
@@ -7,6 +7,7 @@ import (
"sync"
"time"
"github.com/nezhahq/agent/pkg/logger"
"github.com/nezhahq/agent/pkg/util"
pb "github.com/nezhahq/agent/proto"
)
@@ -25,7 +26,7 @@ var (
// UpdateIP 按设置时间间隔更新IP地址的缓存
func FetchIP(useIPv6CountryCode bool) *pb.GeoIP {
util.Println(agentConfig.Debug, "正在更新本地缓存IP信息")
logger.DefaultLogger.Println("正在更新本地缓存IP信息")
wg := new(sync.WaitGroup)
wg.Add(2)
var ipv4, ipv6 string