2026-05-05 13:59:03 +08:00
|
|
|
|
package discover
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
"apigo.cc/go/log"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
const LogTypeDiscover = "discover"
|
|
|
|
|
|
|
|
|
|
|
|
type DiscoverLog struct {
|
|
|
|
|
|
log.BaseLog
|
2026-05-09 14:56:38 +08:00
|
|
|
|
App string `log:"pos:6,color:cyan"`
|
|
|
|
|
|
Method string `log:"pos:7,color:magenta"`
|
|
|
|
|
|
Path string `log:"pos:8,color:blue"`
|
|
|
|
|
|
Node string `log:"pos:9,color:yellow"`
|
|
|
|
|
|
Attempts int `log:"pos:10"`
|
|
|
|
|
|
UsedTime float32 `log:"pos:11,format:%.2fms"`
|
|
|
|
|
|
Error string `log:"pos:12,color:red"`
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (l *DiscoverLog) Reset() {
|
|
|
|
|
|
l.BaseLog.Reset()
|
|
|
|
|
|
l.App = ""
|
|
|
|
|
|
l.Method = ""
|
|
|
|
|
|
l.Path = ""
|
|
|
|
|
|
l.Node = ""
|
|
|
|
|
|
l.Attempts = 0
|
|
|
|
|
|
l.UsedTime = 0
|
|
|
|
|
|
l.Error = ""
|
2026-05-05 21:46:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
|
log.RegisterType(LogTypeDiscover, DiscoverLog{})
|
2026-05-05 13:59:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (ac *AppClient) Log(node string, usedTime float32, err error) {
|
|
|
|
|
|
if ac.Logger == nil {
|
|
|
|
|
|
ac.Logger = log.DefaultLogger
|
|
|
|
|
|
}
|
|
|
|
|
|
if !ac.Logger.CheckLevel(log.INFO) {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
entry := log.GetEntry[DiscoverLog]()
|
2026-05-05 17:34:49 +08:00
|
|
|
|
// 框架会自动调用 fillBase,只需填充业务字段
|
2026-05-05 13:59:03 +08:00
|
|
|
|
entry.App = ac.App
|
|
|
|
|
|
entry.Method = ac.Method
|
|
|
|
|
|
entry.Path = ac.Path
|
|
|
|
|
|
entry.Node = node
|
|
|
|
|
|
entry.Attempts = ac.attempts
|
|
|
|
|
|
entry.UsedTime = usedTime
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
entry.Error = err.Error()
|
|
|
|
|
|
}
|
|
|
|
|
|
ac.Logger.Log(entry)
|
|
|
|
|
|
}
|