package orchestration import ( "crypto/rand" "encoding/hex" "io" "log/slog" "git.yeij.top/AskaEth/Cyrene_v2/internal/logger" ) // sourcedLog 返回标注了来源 "orchestration" 的基础 logger,并把 nil logger // 换成丢弃式 logger,使调度器总能记录日志。 func sourcedLog(l *slog.Logger) *slog.Logger { if l == nil { l = slog.New(slog.NewTextHandler(io.Discard, nil)) } return logger.WithSource(l, "orchestration") } // prefixBytes 是构建子代理 id 前缀所用的随机字节数。 const prefixBytes = 4 // randPrefix 返回子代理 id 的短随机前缀;系统熵源不可用时回退为 "sub"。 func randPrefix() string { var b [prefixBytes]byte if _, err := rand.Read(b[:]); err != nil { return "sub" } return "sub-" + hex.EncodeToString(b[:]) }