dtgvl48608 2017-01-30 10:05
浏览 31
已采纳

如何在日志中识别线程或类似线程?

I am developing in Go language, echo framework.

I am designing a logger and I want to log the equivalent of thread ID to the log, but I do not know a good method.

For example, if login processing is performed at the same time with multiple accesses, it succeeds on one side and fails on one side It can not be determined by looking at the log which failed.

After examining, in Go language goroutine's id exists, but I should not get it, Originally it was said that goroutine was not the same in the same thread.

How can I identify threads? Or is there a package to put them in the log?

I'm sorry if I used the wrong expression as English is not my mother tongue. Thanks.

  • 写回答

2条回答 默认 最新

  • douzai1074 2017-01-30 10:12
    关注

    There is no equivalent of thread id in GoLang for go routines.

    What you may do is create a context and attach a unique id (request id preferably) to it.Let all the functions accept a context aswell. Let the logger library take the context and print the unique id. By using context in this way you can share even for info for the log

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 爬虫爬取网站的一些信息
  • ¥15 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突
  • ¥15 请教一下写代码,代码好难
  • ¥15 iis10中如何阻止别人网站重定向到我的网站
  • ¥15 滑块验证码移动速度不一致问题
  • ¥15 Utunbu中vscode下cern root工作台中写的程序root的头文件无法包含
  • ¥15 麒麟V10桌面版SP1如何配置bonding
  • ¥15 Marscode IDE 如何预览新建的 HTML 文件
  • ¥15 K8S部署二进制集群过程中calico一直报错