简体   繁体   English

如何在 python 中进行基于请求/会话的日志记录?

[英]Ho to do a request/session based logging in python?

I have a web service in which we want to add logs with SessionId/RequestId attached to it.我有一个 web 服务,我们想在其中添加附加了 SessionId/RequestId 的日志。 Tried adding sessionId as part of Filter but when the concurrent requests comes to web service it overwrites the sessionId with new sessionId for all the logs, even for previous request which is running.尝试将 sessionId 添加为过滤器的一部分,但是当并发请求到达 web 服务时,它会用所有日志的新 sessionId 覆盖 sessionId,即使对于正在运行的先前请求也是如此。

You'll need to make sure your session information (or a key to it) is held in a thread local.您需要确保您的 session 信息(或它的密钥)保存在本地线程中。 I wrote a blog post about a similar issue (in that case it was about two different web applications on the same server, but the same principle applies in this case - making sure the contexts of multiple requests are kept isolated from each other).我写了一篇关于类似问题的博客文章(在这种情况下,它是关于同一服务器上的两个不同的 web 应用程序,但同样的原则适用于这种情况 - 确保多个请求的上下文彼此隔离)。 There's too much detail to reproduce here, so refer to the details in the linked post.此处复制的细节太多,因此请参阅链接帖子中的详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM