tags:

views:

178

answers:

1

Hello

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 to this ? [I was thinking of maybe somehow walking the trace until I find a function with "request" in its args]

Thanks in advance

+2  A: 

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.

Carl Meyer
Since this is only a debugging tool, I don't want to start passing around the 'context' between all functions. Looks like a perfect way to insert hooks into a dev server. Thanks !
Murkin