开发者

Django logging with user/ip

I am using the "logging" module to log a very large amount of messages. I would like to add "user" (request.user) to the log. But while it is available in the view function, I don't want to pass it to all helpers.

Does anyone know a way开发者_JAVA技巧 to this ? [I was thinking of maybe somehow walking the trace until I find a function with "request" in its args]

Thanks in advance


The hacky way to do this is to stick the request (or request.user) in threadlocal storage.

The correct and maintainable way is to explicitly pass the data you need into the functions that need it. If doing this seems too onerous, it may reveal a deeper problem in how you've structured your code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜