小编hit*_*lin的帖子

如何获取 Goroutine 的运行时 ID?

如何获取 Goroutine 的运行时 ID?

我从导入的包中获取交错日志 - 一种方法是向每个 goroutine 的日志添加唯一标识符。

我找到了一些参考资料runtime.GoID

func worker() {
    id := runtime.GoID()
    log.Println("Goroutine ID:", id)
}
Run Code Online (Sandbox Code Playgroud)

但看起来现在已经过时/已被删除 - https://pkg.go.dev/runtime

concurrency logging runtime go

4
推荐指数
1
解决办法
5713
查看次数

标签 统计

concurrency ×1

go ×1

logging ×1

runtime ×1