处理此请求时,在所有日志中指定HTTP请求ID的最佳方法
有一个HTTP服务器接受一个线程中的TCP连接,然后将解析的请求推入线程池。当有许多这样的请求时,日志中几乎没有任何意义,因为尚不清楚日志中的条目是指。我想在接受连接和解析的线程中向每个请求发出ID,并在每个日志之前使用这样的ID。问题是如何最好地做到这一点?可以将带有此ID的字符串作为附加参数传递给ThreadPool Worker中调用的每个函数,但看起来非常笨拙。有什么想法如何更优雅地解决这个问题? /zquos.png“ alt =”“在此处输入图像描述”> 我试图在活动图中描述这一点。在这里,通过API,数据库服务未接收有关HTTP请求的信息。因此,没有有关他的身份证的信息。我可以在DB服务的API中添加一个参数,但这会导致强耦合,并且DB服务的API看起来超载
There is an http server that accepts tcp connections in one thread, then the parsed request is pushed into the thread pool. When there are many such requests, there is almost no sense in the logs, because it is not clear which request the entry in the log refers to. I want to issue an id to each request in a thread that accepts a connection and parses, and precede each log with such an id. The question is how best to do it? It is possible to pass a string with this id as an additional parameter to each function that is called in the threadpool worker, but it looks very clumsy. Any ideas how to solve this problem more gracefully?I tried to depict this in an activity diagram. Here, through API, the db service does not receive information about the http request. Therefore, there is no information about his id. I can add an argument to the API of DB service, but this causes strong coupling and the API of DB service will look overloaded
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过简单的参数命名,将其称为trace_log之类的东西,更松散地将DB服务搭配,并在未传递的情况下生成它。这样一来,知道要传递的内容是呼叫功能的责任。
You can more loosely couple the DB service through simple naming of the parameter, call it trace_log or something, and generate it if it isn't passed in. That way it's the responsibility of the calling function to know what to pass down.